package dto

import "time"

// ConversationItem is one backend-unified Inbox conversation row.
type ConversationItem struct {
	ID                   string                    `json:"id"`
	Kind                 string                    `json:"kind"`
	ScopeID              string                    `json:"scopeId"`
	Route                string                    `json:"route"`
	ParentScopeID        string                    `json:"parentScopeId,omitempty"`
	ParentScopeType      string                    `json:"parentScopeType,omitempty"`
	ParentTitle          string                    `json:"parentTitle,omitempty"`
	ParentMessageID      string                    `json:"parentMessageId,omitempty"`
	ParentMessageShortID string                    `json:"parentMessageShortId,omitempty"`
	ParentMessageAuthor  string                    `json:"parentMessageAuthor,omitempty"`
	Title                string                    `json:"title"`
	Subtitle             string                    `json:"subtitle,omitempty"`
	AvatarURL            string                    `json:"avatarUrl,omitempty"`
	Subsystem            string                    `json:"subsystem,omitempty"`
	TeamID               string                    `json:"teamId,omitempty"`
	TeamHandle           string                    `json:"teamHandle,omitempty"`
	TeamDisplayName      string                    `json:"teamDisplayName,omitempty"`
	PeerType             string                    `json:"peerType,omitempty"`
	PeerID               string                    `json:"peerId,omitempty"`
	Preview              string                    `json:"preview,omitempty"`
	LastAuthorName       string                    `json:"lastAuthorName,omitempty"`
	LastMessageAt        *time.Time                `json:"lastMessageAt,omitempty"`
	LastActivityAt       *time.Time                `json:"lastActivityAt,omitempty"`
	PinnedAt             *time.Time                `json:"pinnedAt,omitempty"`
	UnreadCount          int64                     `json:"unreadCount"`
	ManualUnread         bool                      `json:"manualUnread,omitempty"`
	SubscriptionState    string                    `json:"subscriptionState,omitempty"`
	SidebarHidden        bool                      `json:"sidebarHidden,omitempty"`
	Archived             bool                      `json:"archived,omitempty"`
	ReplyCount           int64                     `json:"replyCount,omitempty"`
	LastReplyAt          *time.Time                `json:"lastReplyAt,omitempty"`
	Task                 *ConversationTaskMetadata `json:"task,omitempty"`
}

// ConversationTaskMetadata is the canonical Task payload attached to one
// aggregated task:{scopeId} Inbox row. Activity/message fanout refreshes this
// projection in place; the Inbox never creates one row per Task event.
type ConversationTaskMetadata struct {
	ID                          string         `json:"id"`
	ScopeID                     string         `json:"scopeId"`
	ChannelID                   string         `json:"channelId"`
	Number                      int64          `json:"number"`
	Title                       string         `json:"title"`
	Status                      string         `json:"status"`
	ParentTaskRef               string         `json:"parentTaskRef,omitempty"`
	SourceThreadID              string         `json:"sourceThreadId,omitempty"`
	SourceThreadParentChannelID string         `json:"sourceThreadParentChannelId,omitempty"`
	SourceThreadParentMessageID string         `json:"sourceThreadParentMessageId,omitempty"`
	SourceThreadRef             string         `json:"sourceThreadRef,omitempty"`
	AssigneeProfile             *AuthorProfile `json:"assigneeProfile,omitempty"`
	Route                       string         `json:"route"`
}

// ConversationActionRequest applies one row-level action to a backend-unified
// Inbox conversation.
type ConversationActionRequest struct {
	Action string `json:"action"`
}

// ConversationsBulkActionRequest applies an operation to every conversation
// matching the supplied backend-unified Inbox kind filter.
type ConversationsBulkActionRequest struct {
	Action string   `json:"action"`
	Kinds  []string `json:"kinds,omitempty"`
}

// ConversationsBulkActionResponse returns the effect of a bulk conversation action.
type ConversationsBulkActionResponse struct {
	UpdatedCount int64 `json:"updatedCount"`
}

// ConversationLookupRequest resolves exact member-visible conversation rows.
type ConversationLookupRequest struct {
	ConversationIDs []string `json:"conversationIds"`
}

// ConversationPage is the backend-unified Inbox conversations page.
type ConversationPage struct {
	Items      []ConversationItem `json:"items"`
	HasMore    bool               `json:"hasMore"`
	NextCursor string             `json:"nextCursor,omitempty"`
}
