package service

import "errors"

var (
	ErrRateLimitExceeded = errors.New("rate limit exceeded")
	ErrValidationFailed  = errors.New("validation failed")
)

type classifiedError struct {
	message string
	cause   error
}

func (e *classifiedError) Error() string {
	if e.message != "" {
		return e.message
	}
	if e.cause != nil {
		return e.cause.Error()
	}
	return ""
}

func (e *classifiedError) Unwrap() error {
	return e.cause
}

func newRateLimitError(message string) error {
	return &classifiedError{
		message: message,
		cause:   ErrRateLimitExceeded,
	}
}

func newValidationError(message string) error {
	return &classifiedError{
		message: message,
		cause:   ErrValidationFailed,
	}
}
