package plan

import (
	"context"
	"time"

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

// Service is the narrow browser authoring port. Binding, Invocation, and Run
// deliberately do not appear on this Plan-only surface.
type Service interface {
	Create(context.Context, planmanage.CreateInput) (planmanage.Plan, planmanage.Draft, error)
	List(context.Context, planmanage.ListInput) (planmanage.PlanPage, error)
	Get(context.Context, string, string) (planmanage.Plan, error)
	UpdateMetadata(context.Context, planmanage.UpdateMetadataInput) (planmanage.Plan, error)
	GetDraft(context.Context, string, string) (planmanage.Draft, error)
	SaveDraft(context.Context, planmanage.SaveDraftInput) (planmanage.Draft, error)
	Validate(context.Context, string) planmanage.Validation
	ValidateDraft(context.Context, string, string, int64) (planmanage.Validation, error)
	Publish(context.Context, planmanage.PublishInput) (planmanage.Plan, planmanage.Version, error)
	ListVersions(context.Context, string, string, int, string) (planmanage.VersionPage, error)
	GetVersion(context.Context, string, string, string) (planmanage.Version, error)
	Republish(context.Context, planmanage.RepublishInput) (planmanage.Plan, planmanage.Version, error)
	SetDefault(context.Context, planmanage.PromoteDefaultInput) (planmanage.Plan, error)
	Archive(context.Context, planmanage.LifecycleInput) (planmanage.Plan, error)
	Restore(context.Context, planmanage.LifecycleInput) (planmanage.Plan, error)
}

// PlanAuthoringAuthority is the viewer-specific permission port used by
// browser authoring routes. It is separate from immutable actor provenance.
type PlanAuthoringAuthority interface {
	CanAuthor(context.Context, string, string, string) (bool, error)
}

// AgentEditService is the Workflow product-scope message and exact Agent wake
// port used only by the Builder's AI editing surface.
type AgentEditService interface {
	GetWake(context.Context, string, string) (*planmanage.WakeState, error)
	ListMessages(context.Context, string, string, int64, int) (planmanage.MessagePage, error)
	ListAgents(context.Context, string, string, string, string, string, int) (planmanage.AgentPage, error)
	Request(context.Context, planmanage.RequestInput) (planmanage.RequestResult, error)
	WasWakeActiveAt(context.Context, string, string, time.Time) (bool, error)
}
