package types

import (
	"time"

	"github.com/google/uuid"
)

type PlanStatus string

const (
	PlanStatusDraft      PlanStatus = "draft"
	PlanStatusActive     PlanStatus = "active"
	PlanStatusBlocked    PlanStatus = "blocked"
	PlanStatusCompleted  PlanStatus = "completed"
	PlanStatusCancelled  PlanStatus = "cancelled"
	PlanStatusSuperseded PlanStatus = "superseded"
)

type PlanPriority string

const (
	PlanPriorityLow      PlanPriority = "low"
	PlanPriorityMedium   PlanPriority = "medium"
	PlanPriorityHigh     PlanPriority = "high"
	PlanPriorityCritical PlanPriority = "critical"
)

type Plan struct {
	ID               int64        `json:"id"`
	GUID             uuid.UUID    `json:"guid"`
	Title            string       `json:"title"`
	Description      string       `json:"description"`
	Status           PlanStatus   `json:"status"`
	Priority         PlanPriority `json:"priority"`
	ProjectID        *int64       `json:"project_id,omitempty"`
	Owner            string       `json:"owner,omitempty"`
	DueDate          *time.Time   `json:"due_date,omitempty"`
	CompletedAt      *time.Time   `json:"completed_at,omitempty"`
	ReviewedBy       string       `json:"reviewed_by,omitempty"`
	LastReviewedAt   *time.Time   `json:"last_reviewed_at,omitempty"`
	SupersedesPlanID *int64       `json:"supersedes_plan_id,omitempty"`
	Tags             []string     `json:"tags"`
	CreatedAt        time.Time    `json:"created_at"`
	UpdatedAt        time.Time    `json:"updated_at"`
}

// PlanDetail enriches Plan with all related records, returned by get_plan.
type PlanDetail struct {
	Plan
	DependsOn    []Plan           `json:"depends_on"`
	Blocks       []Plan           `json:"blocks"`
	RelatedPlans []Plan           `json:"related_plans"`
	Skills       []AgentSkill     `json:"skills"`
	Guardrails   []AgentGuardrail `json:"guardrails"`
}

type PlanFilter struct {
	Limit     int
	ProjectID *int64
	Status    string
	Priority  string
	Owner     string
	Tag       string
	Query     string
}

// PlanUpdate describes a partial update; nil pointer fields are not touched.
type PlanUpdate struct {
	Title                 *string
	Description           *string
	Status                *string
	Priority              *string
	Owner                 *string    // "" to clear
	DueDate               *time.Time // nil = no change
	ClearDueDate          bool       // true = set NULL (takes priority over DueDate)
	CompletedAt           *time.Time
	ClearCompletedAt      bool
	ReviewedBy            *string // "" to clear
	MarkReviewed          bool    // sets last_reviewed_at = now()
	SupersedesPlanID      *int64
	ClearSupersedesPlanID bool
	Tags                  *[]string // nil = no change; replace when non-nil
}
