package mediagen

import (
	"time"

	"{{GO_MODULE}}/pkg/routing"
)

// CircuitBreaker is an alias for routing.CircuitBreaker.
//
// IMPORTANT: All cooldown tracking logic is implemented in pkg/routing.
// Do NOT implement custom cooldown logic here. Use routing.CircuitBreaker
// directly for new code.
//
// This alias is provided for backward compatibility with existing code
// that references mediagen.CircuitBreaker.
type CircuitBreaker = routing.CircuitBreaker

// Cooldown period constants - re-exported from routing for convenience.
const (
	// DefaultCooldownPeriod is the cooldown for rate limits and quota errors.
	DefaultCooldownPeriod = routing.DefaultCooldownPeriod

	// TransientCooldownPeriod is the cooldown for transient server errors (503, 500, etc).
	TransientCooldownPeriod = routing.TransientCooldownPeriod
)

// FailureType categorizes errors for cooldown duration selection.
// Re-exported from routing for convenience.
type FailureType = routing.FailureType

// FailureType constants.
const (
	FailureTypeNone      = routing.FailureTypeNone
	FailureTypeRateLimit = routing.FailureTypeRateLimit
	FailureTypeTransient = routing.FailureTypeTransient
)

// NewCircuitBreaker creates a new circuit breaker.
//
// IMPORTANT: Prefer using routing.NewCircuitBreaker directly for new code.
// This function is provided for backward compatibility.
func NewCircuitBreaker(cooldown time.Duration) *CircuitBreaker {
	return routing.NewCircuitBreaker(cooldown)
}

// NewCircuitBreakerWithTransientCooldown creates a circuit breaker with
// custom cooldown periods for rate limits and transient errors.
func NewCircuitBreakerWithTransientCooldown(rateLimitCooldown, transientCooldown time.Duration) *CircuitBreaker {
	return routing.NewCircuitBreakerWithTransientCooldown(rateLimitCooldown, transientCooldown)
}

// ClassifyError determines the failure type for an error.
//
// IMPORTANT: Prefer using routing.ClassifyError directly for new code.
func ClassifyError(err error) FailureType {
	return routing.ClassifyError(err)
}

// IsRateLimitOrQuotaError checks if an error indicates rate limiting or quota exhaustion.
func IsRateLimitOrQuotaError(err error) bool {
	return routing.IsRateLimitError(err)
}

// IsTransientServerError checks if an error indicates a transient server error (5xx).
func IsTransientServerError(err error) bool {
	return routing.IsTransientError(err)
}

// IsCooldownTriggeringError checks if an error should trigger any cooldown.
func IsCooldownTriggeringError(err error) bool {
	return routing.IsCooldownTriggeringError(err)
}
