package errs

import (
	"fmt"

	"gateway/internal/library/errors/code"
)

// ErrInvalidCode is returned when scope, category, or detail is out of range.
var ErrInvalidCode = fmt.Errorf("invalid error code components")

func validateComponents(scope code.Scope, category code.Category, detail code.Detail) error {
	if !scope.Valid() {
		return fmt.Errorf("%w: scope %d exceeds max %d", ErrInvalidCode, scope, code.MaxScope)
	}
	if !category.Valid() {
		return fmt.Errorf("%w: category %d exceeds max %d", ErrInvalidCode, category, code.MaxCategory)
	}
	if !detail.Valid() {
		return fmt.Errorf("%w: detail %d exceeds max %d", ErrInvalidCode, detail, code.MaxDetail)
	}

	return nil
}
