package agent

import "fmt"

// PageErrorKind identifies a deterministic continuation failure. Callers must
// map the kind, not inspect the human-readable message.
type PageErrorKind uint8

const (
	PageErrorMalformed PageErrorKind = iota + 1
	PageErrorQueryMismatch
	PageErrorStaleRevision
	PageErrorStaleAnchor
	PageErrorLimit
)

// PageError is returned by the profile Agent index when a continuation cannot
// be trusted. It is deliberately small so the daemon can preserve a typed
// validation/conflict envelope without exposing profile internals.
type PageError struct {
	Kind   PageErrorKind
	Detail string
}

func (e *PageError) Error() string {
	if e == nil {
		return "agent page error"
	}
	if e.Detail == "" {
		return fmt.Sprintf("agent page error (%d)", e.Kind)
	}
	return e.Detail
}

func NewPageError(kind PageErrorKind, detail string) *PageError {
	return &PageError{Kind: kind, Detail: detail}
}
