package utils

import (
	"fmt"
	"time"

	"github.com/pingcap/errors"
)

const (
	DefaultWaitInterval = 10 * time.Second
)

// 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, errors.Cause(e.Cause))
}
