// Package binding owns the human and Agent transport contracts for
// Workflow Bindings. Persistence and lifecycle rules live behind Service.
package binding

import (
	"context"

	"github.com/tidbcloud/AgentTeam/internal/workflow/bindingmanage"
)

const (
	ActorTypeHuman = bindingmanage.ActorTypeHuman
	ActorTypeAgent = bindingmanage.ActorTypeAgent
)

// Transport code aliases the management-domain values rather than maintaining
// a second, drift-prone Binding model. Request DTOs remain transport-owned;
// owner, actor, principal, workspace, and idempotency fields are injected only
// after authentication.
type Actor = bindingmanage.Actor
type Owner = bindingmanage.Owner
type RevisionRef = bindingmanage.RevisionRef
type Binding = bindingmanage.Binding
type Revision = bindingmanage.Revision
type Diagnostic = bindingmanage.Diagnostic
type Validation = bindingmanage.Validation
type BindingPage = bindingmanage.BindingPage
type RevisionPage = bindingmanage.RevisionPage
type CreateInput = bindingmanage.CreateInput
type ListInput = bindingmanage.ListInput
type UpdateMetadataInput = bindingmanage.UpdateMetadataInput
type ValidateInput = bindingmanage.ValidateInput
type CreateRevisionInput = bindingmanage.CreateRevisionInput
type ListRevisionsInput = bindingmanage.ListRevisionsInput
type ActivateInput = bindingmanage.ActivateInput
type LifecycleInput = bindingmanage.LifecycleInput
type ReplayCommandInput = bindingmanage.ReplayCommandInput
type ReplayCommandResult = bindingmanage.ReplayCommandResult

// CommandReplayService is required only by the authenticated Agent object
// command. Human HTTP handlers keep the ordinary lifecycle Service narrow.
type CommandReplayService interface {
	ReplayCommand(context.Context, bindingmanage.ReplayCommandInput) (bindingmanage.ReplayCommandResult, bool, error)
}

// Service is the narrow lifecycle port consumed by transports. *bindingmanage.Service
// implements this interface directly; the interface keeps handler unit tests
// independent from persistence.
type Service interface {
	Create(context.Context, bindingmanage.CreateInput) (bindingmanage.Binding, bindingmanage.Revision, error)
	List(context.Context, bindingmanage.ListInput) (bindingmanage.BindingPage, error)
	Get(context.Context, string, string) (bindingmanage.Binding, error)
	UpdateMetadata(context.Context, bindingmanage.UpdateMetadataInput) (bindingmanage.Binding, error)
	Validate(context.Context, bindingmanage.ValidateInput) (bindingmanage.Validation, error)
	CreateRevision(context.Context, bindingmanage.CreateRevisionInput) (bindingmanage.Binding, bindingmanage.Revision, error)
	ListRevisions(context.Context, bindingmanage.ListRevisionsInput) (bindingmanage.RevisionPage, error)
	GetRevision(context.Context, string, string, int64) (bindingmanage.Revision, error)
	Activate(context.Context, bindingmanage.ActivateInput) (bindingmanage.Binding, bindingmanage.Revision, error)
	Disable(context.Context, bindingmanage.LifecycleInput) (bindingmanage.Binding, error)
	Archive(context.Context, bindingmanage.LifecycleInput) (bindingmanage.Binding, error)
	Restore(context.Context, bindingmanage.LifecycleInput) (bindingmanage.Binding, error)
}
