package dto

import (
	"time"
)

// TaskExecutionHistoryResponse returns a unified task execution history.
type TaskExecutionHistoryResponse struct {
	Task  Task                       `json:"task"`
	Items []TaskExecutionHistoryItem `json:"items,omitempty"`
}

// TaskExecutionHistoryItem is one task execution timeline item.
type TaskExecutionHistoryItem struct {
	Kind      string    `json:"kind"`
	ID        string    `json:"id"`
	CreatedAt time.Time `json:"createdAt"`
	Payload   any       `json:"payload"`
}

// TaskAnnouncementRequest publishes a task-owned announcement to a source surface.
type TaskAnnouncementRequest struct {
	Intent        string   `json:"intent"`
	Body          string   `json:"body"`
	TargetScopeID string   `json:"targetScopeId,omitempty"`
	AttachmentIDs []string `json:"attachmentIds,omitempty"`
}

// TaskAnnouncementResponse returns the sent announcement message and task note.
type TaskAnnouncementResponse struct {
	Task    Task                 `json:"task"`
	Message AppMessage           `json:"message"`
	Entry   *TaskDiscussionEntry `json:"entry,omitempty"`
}

// TaskNotificationPolicyRequest updates a task notification preference.
type TaskNotificationPolicyRequest struct {
	State     string `json:"state,omitempty"`
	WakeState string `json:"wakeState,omitempty"`
}

// TaskNotificationPolicyResponse wraps the current task-facing notification panel.
type TaskNotificationPolicyResponse struct {
	Task           Task                   `json:"task"`
	ScopeType      string                 `json:"surfaceKind"`
	ScopeID        string                 `json:"surfaceId"`
	Panel          ScopeNotificationPanel `json:"panel"`
	WatcherPreview []AuthorProfile        `json:"watcherPreview"`
	WatcherCount   int                    `json:"watcherCount"`
	MemberCount    int                    `json:"memberCount"`
}

// TaskWatcherPageResponse is a bounded page of the complete explicit watcher
// roster shared by every authorized Task reader.
type TaskWatcherPageResponse struct {
	Watchers     []AuthorProfile `json:"watchers"`
	WatcherCount int             `json:"watcherCount"`
	HasMore      bool            `json:"hasMore"`
	NextCursor   string          `json:"nextCursor,omitempty"`
}

// ScopeNotificationSelfRow is the current user's notification state for a surface.
type ScopeNotificationSelfRow struct {
	State string `json:"state"`
}

// ScopeNotificationAgentRow is one agent wake-policy row for a surface.
type ScopeNotificationAgentRow struct {
	AgentID       string `json:"agentId"`
	AgentMemberID string `json:"agentMemberId"`
	Name          string `json:"name"`
	DisplayName   string `json:"displayName"`
	Visibility    string `json:"visibility"`
	WakeState     string `json:"wakeState"`
}

// ScopeNotificationPanel is the browser-facing notification policy panel for a channel or thread.
type ScopeNotificationPanel struct {
	ScopeID         string                      `json:"surfaceId"`
	ScopeType       string                      `json:"surfaceKind"` // channel, thread, or task.
	ReadOnly        bool                        `json:"readOnly"`
	ReadOnlyReason  string                      `json:"readOnlyReason,omitempty"`
	Self            ScopeNotificationSelfRow    `json:"self"`
	Agents          []ScopeNotificationAgentRow `json:"agents"`
	AgentNextCursor string                      `json:"agentNextCursor,omitempty"`
	AgentHasMore    bool                        `json:"agentHasMore"`
}

// TaskActiveTargetRequest selects a task as a routing target for a thread or agent.
type TaskActiveTargetRequest struct {
	Scope        string `json:"scope,omitempty"`
	AgentID      string `json:"agentId,omitempty"`
	Source       string `json:"source,omitempty"`
	ThreadTarget string `json:"threadTarget,omitempty"`
	Role         string `json:"role,omitempty"`
}

// TaskActiveTarget is the task-facing active target hint returned to clients.
type TaskActiveTarget struct {
	Channel          string `json:"channel"`
	TaskID           string `json:"taskId"`
	TaskNumber       int64  `json:"taskNumber"`
	TaskTitle        string `json:"taskTitle,omitempty"`
	Source           string `json:"source"`
	ThreadTarget     string `json:"threadTarget,omitempty"`
	Scope            string `json:"scope"`
	AgentID          string `json:"agentId,omitempty"`
	Role             string `json:"role,omitempty"`
	RootTaskNumber   int64  `json:"rootTaskNumber,omitempty"`
	ParentTaskRef    string `json:"parentTaskRef,omitempty"`
	SelectedByUserID string `json:"selectedByUserId,omitempty"`
}

// TaskActiveTargetResponse returns set/clear active target state.
type TaskActiveTargetResponse struct {
	Task             Task              `json:"task"`
	ActiveTaskTarget *TaskActiveTarget `json:"activeTaskTarget,omitempty"`
	Cleared          bool              `json:"cleared,omitempty"`
	Scope            string            `json:"scope,omitempty"`
	AgentID          string            `json:"agentId,omitempty"`
}

// TaskActiveTargetsResponse returns persisted task routing targets.
type TaskActiveTargetsResponse struct {
	Task              Task               `json:"task"`
	ActiveTaskTargets []TaskActiveTarget `json:"activeTaskTargets,omitempty"`
}

// TaskCollaboratorRequest mutates one explicit task/thread/channel collaborator.
type TaskCollaboratorRequest struct {
	MemberID  string     `json:"memberId"`
	Role      string     `json:"role,omitempty"`
	ExpiresAt *time.Time `json:"expiresAt,omitempty"`
}

// PrivateAgentContextStateRequest resolves private-agent context visibility for messages.
type PrivateAgentContextStateRequest struct {
	MessageIDs []string                             `json:"messageIds,omitempty"`
	Window     *PrivateAgentContextStateWindowInput `json:"window,omitempty"`
}

// PrivateAgentContextStateWindowInput requests a bounded source-message window.
type PrivateAgentContextStateWindowInput struct {
	AfterSeq  *int64 `json:"afterSeq,omitempty"`
	BeforeSeq *int64 `json:"beforeSeq,omitempty"`
	Limit     int    `json:"limit,omitempty"`
}
