package dto

import "time"

type KnowledgeQACreateSessionRequest struct {
	SessionID        string   `json:"sessionId"`
	RootMessageID    string   `json:"rootMessageId"`
	ThreadChannelID  string   `json:"threadChannelId"`
	UserMessageID    string   `json:"userMessageId"`
	Question         string   `json:"question"`
	Model            string   `json:"model"`
	ReasonLevel      string   `json:"reasonLevel"`
	WebSearchEnabled bool     `json:"webSearchEnabled"`
	KnowledgeBaseIDs []string `json:"knowledgeBaseIds,omitempty"`
	SourceIDs        []string `json:"sourceIds,omitempty"`
}

type KnowledgeQACreateTurnRequest struct {
	UserMessageID    string   `json:"userMessageId"`
	Question         string   `json:"question"`
	KnowledgeBaseIDs []string `json:"knowledgeBaseIds,omitempty"`
	SourceIDs        []string `json:"sourceIds,omitempty"`
}

type KnowledgeQAFeedbackRequest struct {
	Rating  string   `json:"rating"`
	Reasons []string `json:"reasons,omitempty"`
	Comment string   `json:"comment,omitempty"`
}

type KnowledgeQAShareOpenRequest struct {
	Token string `json:"token"`
}

type KnowledgeQAShare struct {
	ID               string    `json:"id"`
	OwnerDisplayName string    `json:"ownerDisplayName"`
	Question         string    `json:"question"`
	Answer           string    `json:"answer"`
	CreatedAt        time.Time `json:"createdAt"`
	LastOpenedAt     time.Time `json:"lastOpenedAt"`
}

type KnowledgeQAShareCreateResponse struct {
	ShareID string `json:"shareId"`
	URL     string `json:"url"`
}

type KnowledgeQAShareResponse struct {
	Share KnowledgeQAShare `json:"share"`
}

type KnowledgeQAShareSummary struct {
	ID               string    `json:"id"`
	OwnerDisplayName string    `json:"ownerDisplayName"`
	Question         string    `json:"question"`
	CreatedAt        time.Time `json:"createdAt"`
	LastOpenedAt     time.Time `json:"lastOpenedAt"`
}

type KnowledgeQAShareListResponse struct {
	Items []KnowledgeQAShareSummary `json:"items"`
}

type KnowledgeQASessionResponse struct {
	Session KnowledgeQASession `json:"session"`
	Turn    KnowledgeQATurn    `json:"turn"`
}

type KnowledgeQASession struct {
	ID               string   `json:"id"`
	ThreadChannelID  string   `json:"threadChannelId"`
	RootMessageID    string   `json:"rootMessageId"`
	Runtime          string   `json:"runtime"`
	ManagedBy        string   `json:"managedBy"`
	Model            string   `json:"model"`
	ReasonLevel      string   `json:"reasonLevel"`
	WebSearchEnabled bool     `json:"webSearchEnabled"`
	KnowledgeBaseIDs []string `json:"knowledgeBaseIds"`
	SourceIDs        []string `json:"sourceIds"`
	Status           string   `json:"status"`
}

type KnowledgeQATurn struct {
	ID                 string                `json:"id"`
	SessionID          string                `json:"sessionId"`
	UserMessageID      string                `json:"userMessageId"`
	AssistantMessageID string                `json:"assistantMessageId"`
	Question           string                `json:"question"`
	Model              string                `json:"model"`
	ReasonLevel        string                `json:"reasonLevel"`
	WebSearchEnabled   bool                  `json:"webSearchEnabled"`
	Status             string                `json:"status"`
	ErrorCode          string                `json:"errorCode,omitempty"`
	DebugModelOutput   string                `json:"debugModelOutput,omitempty"`
	Activities         []KnowledgeQAActivity `json:"activities"`
	Feedback           *KnowledgeQAFeedback  `json:"feedback,omitempty"`
}

type KnowledgeQAFeedback struct {
	ID        string    `json:"id"`
	Rating    string    `json:"rating"`
	Reasons   []string  `json:"reasons"`
	Comment   string    `json:"comment"`
	UpdatedAt time.Time `json:"updatedAt"`
}

type KnowledgeQAFeedbackResponse struct {
	Feedback KnowledgeQAFeedback `json:"feedback"`
}

type KnowledgeQAFeedbackDeleteResponse struct {
	OK bool `json:"ok"`
}

type KnowledgeQAActivity struct {
	ID             string                     `json:"id"`
	Sequence       int64                      `json:"sequence"`
	Kind           string                     `json:"kind"`
	Status         string                     `json:"status"`
	Summary        string                     `json:"summary,omitempty"`
	ToolName       string                     `json:"toolName,omitempty"`
	ModelCalls     int                        `json:"modelCalls,omitempty"`
	Stage          string                     `json:"stage,omitempty"`
	DiagnosticCode string                     `json:"diagnosticCode,omitempty"`
	Counts         *KnowledgeQAActivityCounts `json:"counts,omitempty"`
	CreatedAt      time.Time                  `json:"createdAt"`
	UpdatedAt      time.Time                  `json:"updatedAt"`
}

type KnowledgeQAActivityCounts struct {
	AuthorizedKnowledgeBases  *int `json:"authorizedKnowledgeBases,omitempty"`
	AuthorizedSources         *int `json:"authorizedSources,omitempty"`
	MissingKnowledgeBases     *int `json:"missingKnowledgeBases,omitempty"`
	MissingSources            *int `json:"missingSources,omitempty"`
	UnavailableKnowledgeBases *int `json:"unavailableKnowledgeBases,omitempty"`
	UnavailableSources        *int `json:"unavailableSources,omitempty"`
	PartiallyAvailableSources *int `json:"partiallyAvailableSources,omitempty"`
	ContextTurns              *int `json:"contextTurns,omitempty"`
	SearchCalls               *int `json:"searchCalls,omitempty"`
	ListCalls                 *int `json:"listCalls,omitempty"`
	ReadCalls                 *int `json:"readCalls,omitempty"`
	WebSearchCalls            *int `json:"webSearchCalls,omitempty"`
	WebReadCalls              *int `json:"webReadCalls,omitempty"`
	WebSources                *int `json:"webSources,omitempty"`
	RefCalls                  *int `json:"refCalls,omitempty"`
	ModelCalls                *int `json:"modelCalls,omitempty"`
	SearchedRoots             *int `json:"searchedRoots,omitempty"`
}

type KnowledgeQATurnListResponse struct {
	Turns []KnowledgeQATurn `json:"turns"`
}

type KnowledgeQAHostedModelOption struct {
	ModelReference     string   `json:"modelReference"`
	DisplayName        string   `json:"displayName"`
	Enabled            bool     `json:"enabled"`
	Reasons            []string `json:"reasons,omitempty"`
	ReasonLevels       []string `json:"reasonLevels,omitempty"`
	DefaultReasonLevel string   `json:"defaultReasonLevel,omitempty"`
}

type KnowledgeQAPolicyStatusResponse struct {
	Enabled                   bool                           `json:"enabled"`
	OrganizationEnabled       bool                           `json:"organizationEnabled"`
	Status                    string                         `json:"status"`
	Runtime                   string                         `json:"runtime"`
	ManagedBy                 string                         `json:"managedBy"`
	WorkloadKind              string                         `json:"workloadKind"`
	OrganizationPolicyVersion int64                          `json:"organizationPolicyVersion"`
	Models                    []KnowledgeQAHostedModelOption `json:"models"`
	ReasonLevels              []string                       `json:"reasonLevels"`
	DefaultReasonLevel        string                         `json:"defaultReasonLevel,omitempty"`
}

type KnowledgeQACitationEvidence struct {
	Content   string `json:"content"`
	Path      string `json:"path"`
	Revision  string `json:"revision"`
	LineStart int64  `json:"lineStart"`
	LineEnd   int64  `json:"lineEnd"`
	Truncated bool   `json:"truncated,omitempty"`
}

// KnowledgeQACitationOpenResponse exposes the exact historical excerpt plus a
// server-selected product destination for callers with direct source access,
// or only the bounded excerpt for restricted-evidence callers. Repository
// identity, credentials, trees, and complete files remain hidden.
type KnowledgeQACitationOpenResponse struct {
	Status            string                       `json:"status"`
	OpenMode          string                       `json:"openMode,omitempty"`
	TargetRoute       string                       `json:"targetRoute,omitempty"`
	TargetWorkspaceID string                       `json:"targetWorkspaceId,omitempty"`
	TargetURL         string                       `json:"targetUrl,omitempty"`
	Evidence          *KnowledgeQACitationEvidence `json:"evidence,omitempty"`
}
