"""Pydantic models matching GeoScored API responses."""

from pydantic import BaseModel


class Scan(BaseModel):
    id: str
    url: str
    brand_name: str
    tier: str
    status: str
    overall_score: float | None = None
    grade: str | None = None
    grade_descriptor: str | None = None
    technical_score: float | None = None
    structural_score: float | None = None
    entity_score: float | None = None
    seo_score: float | None = None
    current_stage: str = ""
    progress_pct: int = 0
    error_message: str | None = None
    created_at: str = ""
    updated_at: str = ""
    callback_url: str | None = None
    webhook_secret: str | None = None
    idempotency_key: str | None = None


class ScanList(BaseModel):
    data: list[Scan]
    total: int
    limit: int
    offset: int
    has_more: bool
    cursor_after: str | None = None
    cursor_before: str | None = None


class Check(BaseModel):
    check_id: str
    check_name: str
    pillar: str
    score: float
    severity: str
    summary: str
    details: dict = {}
    recommendations: list[str] = []


class CheckList(BaseModel):
    data: list[Check]
    total: int
    scan_id: str


class Report(BaseModel):
    scan_id: str
    url: str
    overall_score: float
    overall_grade: str
    grade_descriptor: str
    technical_score: float
    structural_score: float
    entity_score: float
    seo_score: float
    total_checks: int
    passing_checks: int
    warning_checks: int
    failing_checks: int
    checks: list[Check]
    marketing_summary: str | None = None
    engineering_summary: str | None = None
    geo_marketing_summary: str | None = None
    geo_engineering_summary: str | None = None
    seo_marketing_summary: str | None = None
    seo_engineering_summary: str | None = None
    access_level: str
    is_lite: bool


class BatchResultItem(BaseModel):
    index: int
    scan: Scan | None = None
    error: dict | None = None


class BatchResult(BaseModel):
    results: list[BatchResultItem]
    total: int
    succeeded: int
    failed: int


class PillarComparison(BaseModel):
    pillar: str
    score_a: float
    score_b: float
    delta: float
    winner: str


class CheckComparison(BaseModel):
    check_id: str
    check_name: str
    pillar: str
    score_a: float | None = None
    score_b: float | None = None
    delta: float | None = None
    winner: str


class CompareResult(BaseModel):
    scan_a: Scan
    scan_b: Scan
    overall_delta: float
    overall_winner: str
    pillars: list[PillarComparison]
    checks: list[CheckComparison]
    warnings: list[str]


class ExportItem(BaseModel):
    id: str
    url: str
    brand_name: str
    tier: str
    status: str
    overall_score: float | None = None
    technical_score: float | None = None
    structural_score: float | None = None
    entity_score: float | None = None
    seo_score: float | None = None
    created_at: str


class ExportData(BaseModel):
    data: list[ExportItem]
    days: int
    total: int
    truncated: bool
