package dto

// AgentTaskLocator identifies a task by its board-relative number.
type AgentTaskLocator struct {
	Channel string `json:"channel,omitempty"`
	Number  int64  `json:"number,omitempty"`
}

// AgentTaskScope is the canonical portable identity of an existing Task scope.
// The server resolves its workspace, board, and Task from authenticated
// storage; clients never need to know a board-relative number.
type AgentTaskScope struct {
	Kind    string `json:"kind"`
	ScopeID string `json:"scopeId"`
}

// AgentTaskParentScope is kept as a semantic alias for the create contract.
type AgentTaskParentScope = AgentTaskScope

// AgentTaskListRequest is the canonical task list/search contract.
type AgentTaskListRequest struct {
	Channel         string   `json:"channel,omitempty"`
	Query           string   `json:"query,omitempty"`
	Status          string   `json:"status,omitempty"`
	IncludeSubtasks bool     `json:"includeSubtasks,omitempty"`
	Limit           int      `json:"limit,omitempty"`
	Cursor          string   `json:"cursor,omitempty"`
	Sort            string   `json:"sort,omitempty"`
	QuickFilters    []string `json:"quickFilters,omitempty"`
}

// AgentTaskGetRequest is the canonical task get contract.
type AgentTaskGetRequest struct {
	AgentTaskLocator
}

// AgentTaskWrite is the unified rich task item accepted by canonical create.
// A length-1 slice carries a single task. Items carrying only Title use the
// bulk create path; a single rich item uses the rich create path. At most one
// item may carry rich fields, since the store cannot create multiple rich
// tasks in one atomic call.
type AgentTaskWrite struct {
	Title       string `json:"title"`
	Description string `json:"description,omitempty"`
	Kind        string `json:"kind,omitempty"`
	Priority    string `json:"priority,omitempty"`
	Assignee    string `json:"assignee,omitempty"`
}

// AgentTaskCreateRequest is the canonical create contract. Only the Tasks
// collection is accepted; a single task is a length-1 slice. Parent, when
// positive, creates subtasks under that parent task on the resolved board
// instead of top-level tasks. Parent and Target are request-level shared
// fields applied to every item in Tasks.
type AgentTaskCreateRequest struct {
	Channel         string                `json:"channel,omitempty"`
	Tasks           []AgentTaskWrite      `json:"tasks,omitempty"`
	Parent          *int64                `json:"parent,omitempty"`
	ParentTaskScope *AgentTaskParentScope `json:"parentTaskScope,omitempty"`
	Target          string                `json:"target,omitempty"`
}

// AgentTaskPatch contains model-supported Task detail and lifecycle mutations.
// Status carries an optional lifecycle status (todo/in_progress/in_review/done);
// it is applied through the unified status operation, not the detail patch.
type AgentTaskPatch struct {
	Status             *string             `json:"status,omitempty"`
	Title              *string             `json:"title,omitempty"`
	Description        *string             `json:"description,omitempty"`
	Kind               *string             `json:"kind,omitempty"`
	Priority           *string             `json:"priority,omitempty"`
	Assignee           *string             `json:"assignee,omitempty"`
	AcceptanceCriteria []TaskChecklistItem `json:"acceptanceCriteria,omitempty"`
	ReviewChecklist    []TaskChecklistItem `json:"reviewChecklist,omitempty"`
	Messages           []string            `json:"messages,omitempty"`
	URLs               []string            `json:"urls,omitempty"`
	Workspaces         []string            `json:"workspaces,omitempty"`
	Blocker            *string             `json:"blocker,omitempty"`
	Parent             *string             `json:"parent,omitempty"`
	Attachments        []string            `json:"attachments,omitempty"`
}

// AgentTaskUpdateRequest is the canonical task update contract.
type AgentTaskUpdateRequest struct {
	AgentTaskLocator
	AgentTaskPatch
}

// AgentTaskCheckpointRequest is the canonical checkpoint contract.
type AgentTaskCheckpointRequest struct {
	AgentTaskLocator
	Summary string `json:"summary,omitempty"`
}

// AgentTaskDeleteRequest deletes one task by board-local number. SubtaskMode
// is optional for leaf tasks and must be promote or delete for parent tasks.
type AgentTaskDeleteRequest struct {
	AgentTaskLocator
	SubtaskMode string `json:"subtaskMode,omitempty"`
}

// AgentTaskDetailResponse returns full detail for one task.
type AgentTaskDetailResponse struct {
	Detail TaskDetail `json:"detail"`
}

// AgentTaskResponse returns one task.
type AgentTaskResponse struct {
	Task Task `json:"task"`
}

// AgentTaskListResponse returns daemon-compatible task list entries.
type AgentTaskListResponse struct {
	ChannelRef string     `json:"channelRef,omitempty"`
	Tasks      []TaskView `json:"tasks"`
	Limit      int        `json:"limit,omitempty"`
	TotalCount int64      `json:"totalCount,omitempty"`
	HasMore    bool       `json:"hasMore,omitempty"`
	NextCursor string     `json:"nextCursor,omitempty"`
}

// AgentCreatedTasksResponse returns created or reused task entries.
type AgentCreatedTasksResponse struct {
	ChannelRef string        `json:"channelRef,omitempty"`
	Tasks      []CreatedTask `json:"tasks"`
}

// AgentTaskSetClaimRequest claims or releases multiple tasks on one board via
// the canonical set-claim action.
type AgentTaskSetClaimRequest struct {
	Channel string  `json:"channel,omitempty"`
	Numbers []int64 `json:"numbers,omitempty"`
	Claimed bool    `json:"claimed,omitempty"`
}

// AgentTaskSetClaimResponse reports the count of tasks claimed or released and
// any per-task failures.
type AgentTaskSetClaimResponse struct {
	Claimed int                     `json:"claimed"`
	Failed  []AgentTaskClaimFailure `json:"failed,omitempty"`
}

type AgentTaskDeleteResponse struct {
	DeletedTaskNumbers  []int64 `json:"deletedTaskNumbers"`
	PromotedTaskNumbers []int64 `json:"promotedTaskNumbers"`
}

// AgentTaskClaimFailure reports one task that could not be claimed or released.
type AgentTaskClaimFailure struct {
	TaskNumber int64  `json:"taskNumber"`
	Reason     string `json:"reason,omitempty"`
}
