package utils

import (
	"errors"
	"fmt"
	"time"

	perrors "github.com/pingcap/errors"
)

var (
	ErrNotFoundToken                     = errors.New("no found this token")
	ErrZeroReplica                       = errors.New("zero replica")
	ErrExtraReplica                      = errors.New("extra replica")
	ErrNotEnoughPod                      = errors.New("not enough pod for assign")
	ErrAssignCacheSizeLimitExceeded      = errors.New("assign cache size limit exceeded")
	ErrKeyspaceMetaServiceGroupMigrating = errors.New("keyspace meta-service group migration in progress")
)

// RequeueAfterError tells the controller to re-queue the resource after RequeueAfter.
// RequeueAfter can be 0 to be re-queue right away.
type RequeueAfterError struct {
	// Options reason for why we need to re-queue.
	Cause error
	// RequeueAfter is the duration after which the request should be enqueued again.
	RequeueAfter time.Duration
}

func (e *RequeueAfterError) Error() string {
	if e.Cause == nil {
		return fmt.Sprintf("requeue in %s", e.RequeueAfter)
	}

	return fmt.Sprintf("requeue in %s due to %s", e.RequeueAfter, perrors.Cause(e.Cause))
}
