package dto

import "time"

// ChannelResponse is the canonical channel detail response.
type ChannelResponse struct {
	ID                string     `json:"id"`
	Name              string     `json:"name"`
	Slug              string     `json:"slug"`
	DisplayName       string     `json:"displayName"`
	Description       string     `json:"description"`
	Visibility        string     `json:"visibility"`
	Subsystem         string     `json:"subsystem,omitempty"`
	Tutorial          bool       `json:"tutorial,omitempty"`
	TeamID            string     `json:"teamId,omitempty"`
	TeamHandle        string     `json:"teamHandle,omitempty"`
	TeamDisplayName   string     `json:"teamDisplayName,omitempty"`
	Joined            bool       `json:"joined"`
	CanInvite         bool       `json:"canInvite"`
	CanManage         bool       `json:"canManage"`
	Archived          bool       `json:"archived"`
	SubscriptionState string     `json:"subscriptionState,omitempty"`
	PinnedAt          *time.Time `json:"pinnedAt,omitempty"`
}

// DiscoverChannelResponse is the response for discoverable channel endpoints.
type DiscoverChannelResponse struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Slug        string `json:"slug"`
	DisplayName string `json:"displayName"`
	Description string `json:"description"`
	Visibility  string `json:"visibility"`
}

// DiscoverChannelPageResponse is one bounded page of discoverable channels.
type DiscoverChannelPageResponse struct {
	Channels   []DiscoverChannelResponse `json:"channels"`
	HasMore    bool                      `json:"hasMore"`
	NextCursor string                    `json:"nextCursor"`
}

// ChannelAccessResponse is the route-facing answer for one channel id.
// It intentionally separates joined channel reads from public join gates so
// browser entrypoints only navigate to /channels/:id and the channel route owns
// access resolution.
type ChannelAccessResponse struct {
	Status          string                   `json:"status"`
	Channel         *ChannelResponse         `json:"channel,omitempty"`
	JoinableChannel *DiscoverChannelResponse `json:"joinableChannel,omitempty"`
}

// ChannelCreateRequest is the request body for POST /api/channels.
type ChannelCreateRequest struct {
	Name string `json:"name"`
}

// ChannelUpdateRequest is the request body for PATCH /api/channels/:channelId.
type ChannelUpdateRequest struct {
	Name        *string `json:"name"`
	Description *string `json:"description"`
	Visibility  *string `json:"visibility"`
}

// ChannelShareCardCreateRequest is the request body for POST /api/channels/:channelId/share-card.
type ChannelShareCardCreateRequest struct {
	TargetChannelID string `json:"targetChannelId"`
}

// ThreadShareCardCreateRequest is the request body for POST /api/threads/:threadChannelId/share-card.
type ThreadShareCardCreateRequest struct {
	TargetScopeID string `json:"targetScopeId"`
}

// OpenDMRequest is the request body for POST /api/channels/dm.
type OpenDMRequest struct {
	AgentID string `json:"agentId"`
	UserID  string `json:"userId"`
}

// AddChannelMemberRequest is the request body for POST /api/channels/:channelId/members.
type AddChannelMemberRequest struct {
	AgentID         string `json:"agentId"`
	UserID          string `json:"userId"`
	ServiceMemberID string `json:"serviceMemberId"`
	Visibility      string `json:"visibility"`
}

// UpdateChannelAgentVisibilityRequest is the request body for
// PATCH /api/v1/workspaces/:workspaceId/channels/:channelId/members/agent/:agentId.
type UpdateChannelAgentVisibilityRequest struct {
	Visibility string `json:"visibility"`
}

// BatchAddChannelMembersRequest is the request body for
// POST /api/channels/:channelId/members/batch.
type BatchAddChannelMembersRequest struct {
	Members []AddChannelMemberRequest `json:"members"`
}

// BatchAddChannelMembersResponse is returned after all requested members are
// added in one all-or-nothing mutation.
type BatchAddChannelMembersResponse struct {
	AddedCount int                       `json:"addedCount"`
	Members    []AddChannelMemberRequest `json:"members"`
}

// ChannelAgentCurrentTaskSummary is the authorized current-channel task payload
// shown in one channel member row.
type ChannelAgentCurrentTaskSummary struct {
	TaskID         string `json:"taskId"`
	ChannelID      string `json:"channelId"`
	TaskNumber     int64  `json:"taskNumber"`
	Title          string `json:"title"`
	Status         string `json:"status"`
	Role           string `json:"role"`
	Route          string `json:"route"`
	LastActivityAt string `json:"lastActivityAt,omitempty"`
}

// ChannelAgentTaskSummary is one visible agent's bounded status summary.
type ChannelAgentTaskSummary struct {
	AgentID     string                          `json:"agentId"`
	State       string                          `json:"state"`
	CurrentTask *ChannelAgentCurrentTaskSummary `json:"currentTask,omitempty"`
	MoreCount   int                             `json:"moreCount,omitempty"`
	UpdatedAt   string                          `json:"updatedAt"`
}

// ChannelAgentTaskSummariesResponse returns summaries for agent IDs that are
// visible members of the scoped channel for the authenticated viewer.
type ChannelAgentTaskSummariesResponse struct {
	Summaries []ChannelAgentTaskSummary `json:"summaries"`
}

// ChannelPermissionRequest is the request body for granting a channel permission.
type ChannelPermissionRequest struct {
	MemberID    string `json:"memberId"`
	UserID      string `json:"userId"`
	DisplayName string `json:"displayName"`
}

// ChannelPermissionResponse is one channel-permission grant row.
type ChannelPermissionResponse struct {
	ID          string    `json:"id"`
	WorkspaceID string    `json:"workspaceId"`
	ChannelID   string    `json:"channelId"`
	MemberID    string    `json:"memberId"`
	UserID      string    `json:"userId"`
	DisplayName string    `json:"displayName"`
	CreatedBy   string    `json:"createdBy"`
	CreatedAt   time.Time `json:"createdAt"`
}
