package types

// Phase - execution phase
type Phase string

// Phase constants define the execution phases for robot agent
const (
	PhaseInspiration Phase = "inspiration" // P0: Clock only
	PhaseGoals       Phase = "goals"       // P1
	PhaseTasks       Phase = "tasks"       // P2
	PhaseRun         Phase = "run"         // P3
	PhaseDelivery    Phase = "delivery"    // P4
	PhaseLearning    Phase = "learning"    // P5
	PhaseHost        Phase = "host"        // V2: Host Agent (human interaction)
)

// AllPhases lists phases in execution order (PhaseHost is excluded — it is a cross-phase service role, not a pipeline stage)
var AllPhases = []Phase{
	PhaseInspiration, PhaseGoals, PhaseTasks,
	PhaseRun, PhaseDelivery, PhaseLearning,
}

// AllConfigurablePhases lists phases that can be bound to custom agents
var AllConfigurablePhases = []Phase{
	PhaseInspiration, PhaseGoals, PhaseTasks,
	PhaseRun, PhaseDelivery, PhaseLearning, PhaseHost,
}

// ClockMode - clock trigger mode
type ClockMode string

// ClockMode constants define the clock trigger modes
const (
	ClockTimes    ClockMode = "times"    // run at specific times
	ClockInterval ClockMode = "interval" // run every X duration
	ClockDaemon   ClockMode = "daemon"   // run continuously
)

// TriggerType - trigger source
type TriggerType string

// TriggerType constants define the trigger sources
const (
	TriggerClock TriggerType = "clock"
	TriggerHuman TriggerType = "human"
	TriggerEvent TriggerType = "event"
)

// ExecStatus - execution status
type ExecStatus string

// ExecStatus constants define the execution status values
const (
	ExecPending    ExecStatus = "pending"
	ExecRunning    ExecStatus = "running"
	ExecPaused     ExecStatus = "paused"
	ExecCompleted  ExecStatus = "completed"
	ExecFailed     ExecStatus = "failed"
	ExecCancelled  ExecStatus = "cancelled"
	ExecConfirming ExecStatus = "confirming" // V2: awaiting human confirmation before running
	ExecWaiting    ExecStatus = "waiting"    // V2: suspended, waiting for human input
)

// RobotStatus - matches __yao.member.robot_status
type RobotStatus string

// RobotStatus constants define the robot status values
const (
	RobotIdle        RobotStatus = "idle"
	RobotWorking     RobotStatus = "working"
	RobotPaused      RobotStatus = "paused"
	RobotError       RobotStatus = "error"
	RobotMaintenance RobotStatus = "maintenance"
)

// InterventionAction - human intervention action
// Format: category.action (e.g., "task.add", "goal.adjust")
type InterventionAction string

// InterventionAction constants define the human intervention actions
const (
	// ActionTaskAdd adds a new task
	ActionTaskAdd InterventionAction = "task.add"
	// ActionTaskCancel cancels a task
	ActionTaskCancel InterventionAction = "task.cancel"
	// ActionTaskUpdate updates task details
	ActionTaskUpdate InterventionAction = "task.update"

	// ActionGoalAdjust modifies current goal
	ActionGoalAdjust InterventionAction = "goal.adjust"
	// ActionGoalAdd adds a new goal
	ActionGoalAdd InterventionAction = "goal.add"
	// ActionGoalComplete marks goal as complete
	ActionGoalComplete InterventionAction = "goal.complete"
	// ActionGoalCancel cancels a goal
	ActionGoalCancel InterventionAction = "goal.cancel"

	// ActionPlanAdd adds to plan queue
	ActionPlanAdd InterventionAction = "plan.add"
	// ActionPlanRemove removes from plan queue
	ActionPlanRemove InterventionAction = "plan.remove"
	// ActionPlanUpdate updates planned item
	ActionPlanUpdate InterventionAction = "plan.update"

	// ActionInstruct is a direct instruction to robot
	ActionInstruct InterventionAction = "instruct"
)

// Priority - task/goal priority
type Priority string

// Priority constants define the priority levels
const (
	PriorityHigh   Priority = "high"
	PriorityNormal Priority = "normal"
	PriorityLow    Priority = "low"
)

// DeliveryType - output delivery type
type DeliveryType string

// DeliveryType constants define the output delivery types
const (
	DeliveryEmail   DeliveryType = "email"   // Send via yao/messenger
	DeliveryWebhook DeliveryType = "webhook" // POST to external URL
	DeliveryProcess DeliveryType = "process" // Call Yao Process
	DeliveryNotify  DeliveryType = "notify"  // In-app notification (future, auto by subscriptions)
)

// DedupResult - deduplication result
type DedupResult string

// DedupResult constants define the deduplication results
const (
	DedupSkip    DedupResult = "skip"    // skip execution
	DedupMerge   DedupResult = "merge"   // merge with existing
	DedupProceed DedupResult = "proceed" // proceed normally
)

// EventSource - event trigger source
type EventSource string

// EventSource constants define the event trigger sources
const (
	EventWebhook  EventSource = "webhook"  // HTTP webhook
	EventDatabase EventSource = "database" // DB change trigger
)

// LearningType - learning entry type
type LearningType string

// LearningType constants define the learning entry types
const (
	LearnExecution LearningType = "execution" // execution record
	LearnFeedback  LearningType = "feedback"  // error/fix feedback
	LearnInsight   LearningType = "insight"   // pattern/tip insight
)

// TaskSource - how task was created
type TaskSource string

// TaskSource constants define how a task was created
const (
	TaskSourceAuto  TaskSource = "auto"  // generated by P2 (task planning)
	TaskSourceHuman TaskSource = "human" // added via human intervention
	TaskSourceEvent TaskSource = "event" // added via event trigger
)

// ExecutorType - task executor type
type ExecutorType string

// ExecutorType constants define the task executor types
const (
	ExecutorAssistant ExecutorType = "assistant"
	ExecutorMCP       ExecutorType = "mcp"
	ExecutorProcess   ExecutorType = "process"
)

// TaskStatus - task execution status
type TaskStatus string

// TaskStatus constants define the task execution status values
const (
	TaskPending      TaskStatus = "pending"
	TaskRunning      TaskStatus = "running"
	TaskCompleted    TaskStatus = "completed"
	TaskFailed       TaskStatus = "failed"
	TaskSkipped      TaskStatus = "skipped"
	TaskCancelled    TaskStatus = "cancelled"
	TaskWaitingInput TaskStatus = "waiting_input" // V2: task suspended, waiting for human input
)

// InsertPosition - where to insert task in queue
type InsertPosition string

// InsertPosition constants define where to insert task in queue
const (
	InsertFirst InsertPosition = "first" // insert at beginning (highest priority)
	InsertLast  InsertPosition = "last"  // append at end (default)
	InsertNext  InsertPosition = "next"  // insert after current task
	InsertAt    InsertPosition = "at"    // insert at specific index (use AtIndex)
)

// ExecutorMode - executor mode for robot execution
type ExecutorMode string

// ExecutorMode constants define the executor modes
const (
	// ExecutorStandard uses real Agent calls (production mode)
	ExecutorStandard ExecutorMode = "standard"
	// ExecutorDryRun simulates execution without LLM calls (testing/demo)
	ExecutorDryRun ExecutorMode = "dryrun"
	// ExecutorSandbox runs in container-isolated environment (NOT IMPLEMENTED)
	// Requires Docker/gVisor/Firecracker infrastructure
	ExecutorSandbox ExecutorMode = "sandbox"
)

// HostAction defines structured instructions from Host Agent to Manager
type HostAction string

// HostAction constants
const (
	HostActionConfirm   HostAction = "confirm"        // Confirm execution plan
	HostActionAdjust    HostAction = "adjust"         // Adjust goals/tasks
	HostActionAddTask   HostAction = "add_task"       // Inject a new task
	HostActionSkip      HostAction = "skip"           // Skip waiting task
	HostActionInjectCtx HostAction = "inject_context" // Add context to waiting task
	HostActionCancel    HostAction = "cancel"         // Cancel execution
)

// InteractSource defines the source of an interact request
type InteractSource string

// InteractSource constants
const (
	InteractSourceUI      InteractSource = "ui"      // User via Mission Control UI
	InteractSourceEmail   InteractSource = "email"   // Incoming email
	InteractSourceWebhook InteractSource = "webhook" // External webhook
	InteractSourceA2A     InteractSource = "a2a"     // Agent-to-agent
	InteractSourceCron    InteractSource = "cron"    // Scheduled cron
)

// IsValid checks if the executor mode is valid
func (m ExecutorMode) IsValid() bool {
	switch m {
	case ExecutorStandard, ExecutorDryRun, ExecutorSandbox, "":
		return true
	}
	return false
}

// GetDefault returns the default executor mode if empty
func (m ExecutorMode) GetDefault() ExecutorMode {
	if m == "" {
		return ExecutorStandard
	}
	return m
}
