package channeladmin

import "errors"

// Service-level sentinel errors. Handlers map these to stable HTTP/Exec error
// codes; they never carry secrets or internal cause text.
var (
	ErrValidation        = errors.New("channel management: invalid request")
	ErrAgentOwnerMissing = errors.New("channel management: agent has no human execution owner")
	ErrRequestIdConflict = errors.New("channel management: request id conflict")
	ErrNotFound          = errors.New("channel management: channel not found")
	ErrForbidden         = errors.New("channel management: forbidden")
	ErrConflict          = errors.New("channel management: conflict")
	ErrSlugConflict      = errors.New("channel management: channel slug conflict")
	ErrQuotaExceeded     = errors.New("channel management: quota exceeded")
	ErrVersionConflict   = errors.New("channel management: channel version conflict")
	ErrMemberConflict    = errors.New("channel management: member mutation conflict")
)

// errReceiptPKConflict signals that RecordReceipt hit the composite idempotency
// primary key: a concurrent request with the same (workspace, agent, requestId)
// committed first and this transaction must roll back. The caller re-opens a
// read-only receipt lookup to replay the winner instead of surfacing a blind
// conflict. It is internal; handlers never see it directly.
var errReceiptPKConflict = errors.New("channel management: receipt idempotency key already committed")

// errReceiptReservedNotVisible is returned when a loser idempotency request
// collided on the receipt primary key but could not yet read the winner's
// committed result (a transient visibility window: TiDB hides the winner's
// uncommitted receipt insert from the loser's read-only lookup). It is an
// INTERNAL error: the client must retry the SAME request id, whose pre-lookup
// then exact-replays the winner's committed result. It must NOT surface as a 409
// request-id conflict — that would induce a fresh request id and risk a
// duplicate mutation. Handlers map it to a 5xx/internal code, never 409.
var errReceiptReservedNotVisible = errors.New("channel management: idempotency receipt reserved but result not yet visible")
