package connector_inbound

import "errors"

// Sentinel errors returned by this package.
var (
	// ErrUnknownScheme is returned by [NewSignatureVerifier] when the config's
	// Scheme is not in the closed v1 set.
	ErrUnknownScheme = errors.New("connector_inbound: unknown signature scheme")

	// ErrUnknownTemplateToken is returned by [NewSignatureVerifier] when the
	// SigningTemplate contains a token not in the closed v1 set. This is a
	// deployment-configuration bug, NOT a client error — unknown tokens indicate
	// a pack-config mismatch with the platform binary's scheme implementation.
	ErrUnknownTemplateToken = errors.New("connector_inbound: signing template contains unknown token")

	// ErrInvalidSchemeConfig is returned by [NewSignatureVerifier] when required
	// config fields are missing or invalid.
	ErrInvalidSchemeConfig = errors.New("connector_inbound: invalid signature scheme config")

	// ErrInvalidParserConfig is returned by [NewEnvelopeParser] when the
	// EnvelopeMappingConfig fails validation.
	ErrInvalidParserConfig = errors.New("connector_inbound: invalid envelope parser config")

	// ErrSourceRecordInactive is returned only after a pack-declared confirmation
	// probe successfully reads a source record that an ordinary active-record read
	// omitted. Workers treat this as a terminal non-failure and skip the claimed
	// event without handing it to Flow or Runtime. An empty or failed probe must
	// never wrap this sentinel.
	ErrSourceRecordInactive = errors.New("connector_inbound: source record confirmed inactive")

	// errFlowPanic wraps a panic recovered from inside a Flow invocation
	// (ExecuteFlow / ExecuteFlowVersion). The worker call-site recovers the
	// panic and returns a nil FlowResult plus this error so the normal
	// failure-routing (failWithSyncState → MarkFailed for a single event,
	// finalizeBatchFailureOrdered for a batch group) finalizes the event on the
	// genuine-failure budget instead of crashing the in-process worker goroutine.
	errFlowPanic = errors.New("connector_inbound: flow execution panicked")

	// errWorkerPanic wraps a panic recovered by the per-iteration backstop around
	// the claimed-event processing body — a panic OUTSIDE the Flow call
	// (prepare/coalesce/buildFlowInputs/batchRead/decode). The backstop finalizes
	// the whole in-flight unit (an accumulating batch group and/or a loose claimed
	// row) so no claimed row is stranded in 'processing' to re-surface at the
	// stale-reclaim window.
	errWorkerPanic = errors.New("connector_inbound: worker iteration panicked")
)
