# src/ihyee/models.py
"""Pydantic response models for the ihyee API."""
from __future__ import annotations

from typing import List, Optional

from pydantic import BaseModel


class ExtractedLink(BaseModel):
    url: str
    text: str
    context: str = ""


class TextContent(BaseModel):
    title: Optional[str] = None
    full_text: Optional[str] = None
    summary: Optional[str] = None
    author: str = "Unknown"
    date_published: str = "Unknown"
    links: List[ExtractedLink] = []
    error: Optional[str] = None


class ImageContent(BaseModel):
    url: str
    alt: str = ""


class DocumentContent(BaseModel):
    s3_url: str
    original_url: str
    content_type: str
    size_bytes: int


class ChunkCitation(BaseModel):
    text: str
    url: str


class RagChunk(BaseModel):
    id: str
    heading_path: List[str]
    content: str
    content_format: str = "text"
    relevance_score: float
    token_count: int
    citations: List[ChunkCitation] = []


class RagContent(BaseModel):
    content_type: str
    search_engine_rank: int
    relevance_score: float
    title: str
    author: str = "Unknown"
    date_published: Optional[str] = None
    chunks: List[RagChunk]
    total_tokens: int
    links: List[ExtractedLink] = []


class ContentItem(BaseModel):
    type: str
    url: Optional[str] = None
    text: Optional[TextContent] = None
    rag: Optional[RagContent] = None
    image_url: Optional[ImageContent] = None
    document: Optional[DocumentContent] = None


class ResponseMeta(BaseModel):
    search_time_ms: Optional[int] = None
    pages_fetched: int = 0
    pages_rendered: int = 0
    content_mode: str = "both"
    degraded: bool = False
    render_skipped: Optional[str] = None
    quota_warning: Optional[str] = None
    total_chunks: Optional[int] = None
    total_tokens: Optional[int] = None


class SearchResponse(BaseModel):
    query: str
    results_count: int
    content: List[ContentItem]
    meta: ResponseMeta


class FetchResponse(BaseModel):
    content: List[ContentItem]
    meta: ResponseMeta
