package ucca

import "time"

// LegalSearchResult represents a single search result from the compliance corpus.
type LegalSearchResult struct {
	Text            string  `json:"text"`
	RegulationCode  string  `json:"regulation_code"`
	RegulationName  string  `json:"regulation_name"`
	RegulationShort string  `json:"regulation_short"`
	Category        string  `json:"category"`
	Article         string  `json:"article,omitempty"`
	Paragraph       string  `json:"paragraph,omitempty"`
	Pages           []int   `json:"pages,omitempty"`
	SourceURL       string  `json:"source_url"`
	Score           float64 `json:"score"`
}

// LegalContext represents aggregated legal context for an assessment.
type LegalContext struct {
	Query            string              `json:"query"`
	Results          []LegalSearchResult `json:"results"`
	RelevantArticles []string            `json:"relevant_articles"`
	Regulations      []string            `json:"regulations"`
	GeneratedAt      time.Time           `json:"generated_at"`
}

// CERegulationInfo describes an available regulation in the corpus.
type CERegulationInfo struct {
	ID       string `json:"id"`
	NameDE   string `json:"name_de"`
	NameEN   string `json:"name_en"`
	Short    string `json:"short"`
	Category string `json:"category"`
}

// ScrollChunkResult represents a single chunk from the scroll/list endpoint.
type ScrollChunkResult struct {
	ID              string `json:"id"`
	Text            string `json:"text"`
	RegulationCode  string `json:"regulation_code"`
	RegulationName  string `json:"regulation_name"`
	RegulationShort string `json:"regulation_short"`
	Category        string `json:"category"`
	Article         string `json:"article,omitempty"`
	Paragraph       string `json:"paragraph,omitempty"`
	SourceURL       string `json:"source_url,omitempty"`
}

// --- Internal Qdrant / Ollama HTTP types ---

type ollamaEmbeddingRequest struct {
	Model  string `json:"model"`
	Prompt string `json:"prompt"`
}

type ollamaEmbeddingResponse struct {
	Embedding []float64 `json:"embedding"`
}

type qdrantSearchRequest struct {
	Vector      []float64     `json:"vector"`
	Limit       int           `json:"limit"`
	WithPayload bool          `json:"with_payload"`
	Filter      *qdrantFilter `json:"filter,omitempty"`
}

type qdrantFilter struct {
	Should []qdrantCondition `json:"should,omitempty"`
	Must   []qdrantCondition `json:"must,omitempty"`
}

type qdrantCondition struct {
	Key   string      `json:"key"`
	Match qdrantMatch `json:"match"`
}

type qdrantMatch struct {
	Value string `json:"value"`
}

type qdrantSearchResponse struct {
	Result []qdrantSearchHit `json:"result"`
}

type qdrantSearchHit struct {
	ID      interface{}            `json:"id"`
	Score   float64                `json:"score"`
	Payload map[string]interface{} `json:"payload"`
}

type qdrantQueryRequest struct {
	Prefetch    []qdrantPrefetch `json:"prefetch"`
	Query       *qdrantFusion    `json:"query"`
	Limit       int              `json:"limit"`
	WithPayload bool             `json:"with_payload"`
	Filter      *qdrantFilter    `json:"filter,omitempty"`
}

type qdrantPrefetch struct {
	Query  []float64     `json:"query"`
	Limit  int           `json:"limit"`
	Filter *qdrantFilter `json:"filter,omitempty"`
}

type qdrantFusion struct {
	Fusion string `json:"fusion"`
}

type qdrantQueryResponse struct {
	Result []qdrantSearchHit `json:"result"`
}

type qdrantTextIndexRequest struct {
	FieldName   string                `json:"field_name"`
	FieldSchema qdrantTextFieldSchema `json:"field_schema"`
}

type qdrantTextFieldSchema struct {
	Type      string `json:"type"`
	Tokenizer string `json:"tokenizer"`
	MinLen    int    `json:"min_token_len,omitempty"`
	MaxLen    int    `json:"max_token_len,omitempty"`
}

type qdrantScrollRequest struct {
	Limit       int         `json:"limit"`
	Offset      interface{} `json:"offset,omitempty"`
	WithPayload bool        `json:"with_payload"`
	WithVectors bool        `json:"with_vectors"`
}

type qdrantScrollResponse struct {
	Result struct {
		Points         []qdrantScrollPoint `json:"points"`
		NextPageOffset interface{}         `json:"next_page_offset"`
	} `json:"result"`
}

type qdrantScrollPoint struct {
	ID      interface{}            `json:"id"`
	Payload map[string]interface{} `json:"payload"`
}
