import uuid
from datetime import datetime

from pydantic import BaseModel


class CitationResponse(BaseModel):
    id: uuid.UUID
    query_id: uuid.UUID
    platform: str
    cited: bool
    citation_position: int | None
    citation_text: str | None
    competitor_brands: list[str]
    confidence: float | None
    match_type: str | None
    # 引用源分析字段
    data_source: str | None = None
    source_urls: list[str] | None = None
    source_titles: list[str] | None = None
    citation_contexts: list[str] | None = None
    ai_response_text: str | None = None
    queried_at: datetime

    model_config = {"from_attributes": True}


class CitationListResponse(BaseModel):
    items: list[CitationResponse]
    total: int


class PlatformStats(BaseModel):
    queries: int
    citations: int
    rate: float
    avg_position: float | None


class TrendItem(BaseModel):
    date: str
    citations: int


class CitationStatsResponse(BaseModel):
    total_queries: int
    total_citations: int
    citation_rate: float
    avg_position: float | None
    by_platform: dict[str, PlatformStats]
    trend: list[TrendItem]


class RunNowResponse(BaseModel):
    task_id: uuid.UUID
    status: str
    message: str
