package storecontract import ( "context" "time" "github.com/samcharles93/archie-core/internal/domain/binding" "github.com/samcharles93/archie-core/internal/domain/workflow/task" ) // BindingStore persists bindings and their draft -> pending_approval -> // armed states. type BindingStore interface { InsertBinding(ctx context.Context, b binding.Binding) (string, error) GetBinding(ctx context.Context, id string) (*binding.Binding, error) ListBindings(ctx context.Context) ([]binding.Binding, error) UpdateBinding(ctx context.Context, b binding.Binding) error DeleteBinding(ctx context.Context, id string) error ApproveBinding(ctx context.Context, id string) error PauseBinding(ctx context.Context, id string) error ResumeBinding(ctx context.Context, id string) error } // DispatchLedger reads the binding dispatch ledger. type DispatchLedger interface { // ListDispatches returns the newest ledger rows matching filter. ListDispatches(ctx context.Context, filter DispatchFilter) ([]Dispatch, error) } // Dispatch is one binding/capture ledger row: the task it started, or the // reason it started none. type Dispatch struct { BindingID string `json:"binding_id"` BindingVersion int64 `json:"binding_version"` CaptureID string `json:"capture_id"` TaskID int64 `json:"task_id,omitempty"` Reason string `json:"reason,omitempty"` DispatchedAt time.Time `json:"dispatched_at"` } // DispatchFilter narrows ListDispatches; empty fields match any row. type DispatchFilter struct { BindingID string CaptureID string TaskID int64 Limit int } // BindingDispatcher looks up armed bindings, lists undispatched captures and // records dispatches. type BindingDispatcher interface { RecordDispatch( ctx context.Context, bindingID string, bindingVersion int64, captureID string, // taskID addresses the SQLite-owned task tables, which are not // migrating: it stays an integer on purpose. A dispatch that starts // a task is recorded by EnqueueBindingTask instead. taskID int64, // reason is empty for a dispatch and names the terminal outcome of // an evaluation that started no task. reason string, ) error ListUndispatchedCaptures(ctx context.Context, bindings []string, limit int) ([]CapturedEvent, error) } // BindingTaskCreator is the single-method consumer-facing surface for // enqueueing a task triggered by a binding. Splitting it off TaskLifecycle // keeps the lifecycle surface narrow (8 methods, the interfacebloat limit) // and keeps the binding-specific shape on the binding interfaces. type BindingTaskCreator interface { // EnqueueBindingTask claims the binding's dispatch of captureID in the // ledger, enqueues the task and records its provenance as one unit: an // error leaves none of them, and a delivery already dispatched for the // binding returns ErrAlreadyDispatched. EnqueueBindingTask(ctx context.Context, owner, repo, title, body, wf, identity, bindingID string, bindingVersion int, captureID string, inputs map[string]any) (*task.Task, error) } // PlaybookDispatcher records a playbook action dispatch before its side // effect runs, returning ErrAlreadyDispatched for a duplicate. // DeletePlaybookDispatches deletes one playbook's records. type PlaybookDispatcher interface { RecordPlaybookDispatch(ctx context.Context, playbookID, playbookVersion, eventID, actionID string) error DeletePlaybookDispatches(ctx context.Context, playbookID string) error }