package dto

import "time"

// TaskCollaboratorSource explains why a member has effective task access.
type TaskCollaboratorSource struct {
	ScopeType  string `json:"scopeType"`
	ScopeID    string `json:"scopeId"`
	RelationID string `json:"relationId"`
	Role       string `json:"role"`
}

// TaskCollaborator is one explicit collaborator row on a task/channel/thread surface.
type TaskCollaborator struct {
	ID                     string         `json:"id"`
	ScopeType              string         `json:"scopeType"`
	ScopeID                string         `json:"scopeId"`
	ExecutionOwnerMemberID string         `json:"executionOwnerMemberId"`
	MemberID               string         `json:"memberId"`
	MemberProfile          *AuthorProfile `json:"memberProfile,omitempty"`
	// Member is retained for old task collaborator clients and must be
	// derived from MemberProfile at API/Web/daemon boundaries.
	Member          TaskActor      `json:"member"`
	Role            string         `json:"role"`
	AddedByMemberID string         `json:"addedByMemberId"`
	AddedByProfile  *AuthorProfile `json:"addedByProfile,omitempty"`
	// AddedBy is retained for old task collaborator clients and must be
	// derived from AddedByProfile at API/Web/daemon boundaries.
	AddedBy              TaskActor      `json:"addedBy"`
	AddedAt              time.Time      `json:"addedAt"`
	NotificationState    string         `json:"notificationState,omitempty"`
	NotificationQueuedAt *time.Time     `json:"notificationQueuedAt,omitempty"`
	NotifiedAt           *time.Time     `json:"notifiedAt,omitempty"`
	ExpiresAt            *time.Time     `json:"expiresAt,omitempty"`
	LeftAt               *time.Time     `json:"leftAt,omitempty"`
	RemovedAt            *time.Time     `json:"removedAt,omitempty"`
	RemovedByMemberID    string         `json:"removedByMemberId,omitempty"`
	RemovedByProfile     *AuthorProfile `json:"removedByProfile,omitempty"`
	// RemovedBy is retained for old task collaborator clients and must be
	// derived from RemovedByProfile at API/Web/daemon boundaries.
	RemovedBy *TaskActor `json:"removedBy,omitempty"`
	Active    bool       `json:"active"`
}

type AgentCollaboratorSource struct {
	ScopeType          string     `json:"scopeType"`
	ScopeID            string     `json:"scopeId"`
	ScopeDisplayName   string     `json:"scopeDisplayName,omitempty"`
	ChannelID          string     `json:"channelId,omitempty"`
	ChannelDisplayName string     `json:"channelDisplayName,omitempty"`
	RelationID         string     `json:"relationId"`
	Role               string     `json:"role"`
	ExpiresAt          *time.Time `json:"expiresAt,omitempty"`
	Active             bool       `json:"active"`
}

type AgentCollaboratorSummary struct {
	MemberID      string         `json:"memberId"`
	MemberProfile *AuthorProfile `json:"memberProfile,omitempty"`
	// Member is retained for old collaborator clients and must be derived from
	// MemberProfile at API/Web/daemon boundaries.
	Member            TaskActor                 `json:"member"`
	ScopeCount        int                       `json:"scopeCount"`
	SoonExpiringCount int                       `json:"soonExpiringCount,omitempty"`
	Sources           []AgentCollaboratorSource `json:"sources,omitempty"`
}

type ListAgentCollaboratorsResponse struct {
	ExecutionOwnerMemberID string         `json:"executionOwnerMemberId"`
	OwnerProfile           *AuthorProfile `json:"ownerProfile,omitempty"`
	// Owner is retained for old collaborator clients and must be derived from
	// OwnerProfile at API/Web/daemon boundaries.
	Owner                    TaskActor                  `json:"owner"`
	SourceScopeDisplayName   string                     `json:"sourceScopeDisplayName,omitempty"`
	SourceChannelDisplayName string                     `json:"sourceChannelDisplayName,omitempty"`
	People                   []AgentCollaboratorSummary `json:"people,omitempty"`
	Collaborators            []AgentCollaboratorSummary `json:"collaborators,omitempty"`
}

type ListTaskCollaboratorsResponse struct {
	// ExecutionOwnerMemberId is the authoritative server-derived execution owner
	// of the scope (never the viewer). It resolves even when the collaborator
	// list is empty so the request-access entry point has its owner.
	ExecutionOwnerMemberID string         `json:"executionOwnerMemberId"`
	OwnerProfile           *AuthorProfile `json:"ownerProfile,omitempty"`
	// Owner is retained for old collaborator clients and must be derived from
	// OwnerProfile at API/Web/daemon boundaries.
	Owner         TaskActor          `json:"owner"`
	Collaborators []TaskCollaborator `json:"collaborators,omitempty"`
}

type TaskCollaboratorResponse struct {
	Collaborator TaskCollaborator `json:"collaborator"`
}

// EffectiveTaskCollaborator is one explicit or inherited collaborator.
type EffectiveTaskCollaborator struct {
	MemberID      string         `json:"memberId"`
	MemberProfile *AuthorProfile `json:"memberProfile,omitempty"`
	// Member is retained for old collaborator clients and must be derived from
	// MemberProfile at API/Web/daemon boundaries.
	Member  TaskActor                `json:"member"`
	Role    string                   `json:"role"`
	Sources []TaskCollaboratorSource `json:"sources"`
}

type ListEffectiveTaskCollaboratorsResponse struct {
	ExecutionOwnerMemberID string         `json:"executionOwnerMemberId"`
	OwnerProfile           *AuthorProfile `json:"ownerProfile,omitempty"`
	// Owner is retained for old collaborator clients and must be derived from
	// OwnerProfile at API/Web/daemon boundaries.
	Owner         TaskActor                   `json:"owner"`
	People        []EffectiveTaskCollaborator `json:"people,omitempty"`
	Collaborators []EffectiveTaskCollaborator `json:"collaborators,omitempty"`
}

type PrivateAgentContextEligibilityState string

type PrivateAgentContextRelationSource struct {
	Kind       string `json:"kind"`
	ScopeType  string `json:"scopeType,omitempty"`
	ScopeID    string `json:"scopeId,omitempty"`
	RelationID string `json:"relationId,omitempty"`
	Label      string `json:"label,omitempty"`
}

type PrivateAgentContextState struct {
	MessageID       string                              `json:"messageId"`
	State           PrivateAgentContextEligibilityState `json:"state"`
	TargetScopeType string                              `json:"targetScopeType"`
	TargetScopeID   string                              `json:"targetScopeId"`
	Relation        *PrivateAgentContextRelationSource  `json:"relation,omitempty"`
	CanShare        bool                                `json:"canShare"`
	CanWake         bool                                `json:"canWake"`
}

type ResolvePrivateAgentContextStateResponse struct {
	States []PrivateAgentContextState `json:"states,omitempty"`
}

type ResolvePrivateAgentContextContributionCapabilityResponse struct {
	TargetScopeType        string                             `json:"targetScopeType"`
	TargetScopeID          string                             `json:"targetScopeId"`
	ExecutionOwnerMemberID string                             `json:"executionOwnerMemberId"`
	Relation               string                             `json:"relation"`
	RelationSource         *PrivateAgentContextRelationSource `json:"relationSource,omitempty"`
	CanContributeContext   bool                               `json:"canContributeContext"`
	CanWake                bool                               `json:"canWake"`
	CanShare               bool                               `json:"canShare"`
}

type PrivateAgentMentionCandidate struct {
	ID           string         `json:"id"`
	Name         string         `json:"name"`
	DisplayName  string         `json:"displayName"`
	MemberID     string         `json:"memberId,omitempty"`
	AvatarURL    string         `json:"avatarUrl"`
	OwnerProfile *AuthorProfile `json:"ownerProfile,omitempty"`
	// OwnerMemberID/OwnerUserID/OwnerName/OwnerDisplayName are legacy
	// compatibility aliases. New API/Web code must derive owner identity from
	// OwnerProfile.
	OwnerMemberID    string                             `json:"ownerMemberId"`
	OwnerUserID      string                             `json:"ownerUserId,omitempty"`
	OwnerName        string                             `json:"ownerName,omitempty"`
	OwnerDisplayName string                             `json:"ownerDisplayName"`
	Relation         string                             `json:"relation"`
	RelationSource   *PrivateAgentContextRelationSource `json:"relationSource,omitempty"`
}

type ListPrivateAgentMentionCandidatesResponse struct {
	Candidates []PrivateAgentMentionCandidate `json:"candidates,omitempty"`
}

// CollaboratorRequestSubmitRequest is the Human "request to become a
// collaborator" payload. The requester identity and execution owner are derived
// server-side; only the target + role/expiry facts are client-supplied.
type CollaboratorRequestSubmitRequest struct {
	ScopeType             string     `json:"scopeType"`
	ScopeID               string     `json:"scopeId"`
	Role                  string     `json:"role,omitempty"`
	CollaboratorExpiresAt *time.Time `json:"collaboratorExpiresAt,omitempty"`
	ClientRequestID       string     `json:"clientRequestId"`
}

// CollaboratorRequestSubmitResponse reports the created (or replayed) request.
type CollaboratorRequestSubmitResponse struct {
	ApprovalID string `json:"approvalId,omitempty"`
	RequestID  string `json:"requestId,omitempty"`
	Status     string `json:"status"`
	Created    bool   `json:"created"`
}

// CollaboratorRequestStatus is the requester-facing request lifecycle row.
type CollaboratorRequestStatus struct {
	RequestID             string     `json:"requestId"`
	ApprovalID            string     `json:"approvalId"`
	RequesterMemberID     string     `json:"requesterMemberId"`
	OwnerMemberID         string     `json:"ownerMemberId"`
	ScopeType             string     `json:"scopeType"`
	ScopeID               string     `json:"scopeId"`
	Role                  string     `json:"role"`
	CollaboratorExpiresAt *time.Time `json:"collaboratorExpiresAt,omitempty"`
	ApprovalExpiresAt     *time.Time `json:"approvalExpiresAt,omitempty"`
	Status                string     `json:"status"`
	GrantedAt             *time.Time `json:"grantedAt,omitempty"`
	CreatedAt             time.Time  `json:"createdAt"`
}

// CollaboratorRequestListResponse is the requester's request status surface.
type CollaboratorRequestListResponse struct {
	Requests []CollaboratorRequestStatus `json:"requests"`
}

// CollaboratorRequestCancelRequest cancels a pending request by its applicant.
type CollaboratorRequestCancelRequest struct {
	ClientCancellationID string `json:"clientCancellationId"`
}
