from __future__ import annotations

from datetime import datetime

from repo_core.base.models import DomainModel


class CodalStatementDetail(DomainModel):
    """A single tab's worth of data from a codal.ir statement detail page.

    One statement can have multiple detail rows — one per tab.
    Keyed by ``(statement_id, tab_slug)``.
    """

    # -- Identity -------------------------------------------------------
    id: str
    statement_id: str    # FK → codal_statement_listings.statement_id
    tab_slug: str
    tab_name: str | None = None

    # -- Tab content ----------------------------------------------------
    tab_url: str | None = None
    raw_html: str | None = None

    # -- Attachments (JSON array) ---------------------------------------
    attachments: list[dict] | None = None

    # -- Timing ---------------------------------------------------------
    crawl_time: datetime | None = None
    parse_time: datetime | None = None

    # -- Status ---------------------------------------------------------
    status: str | None = None
    error_message: str | None = None

    # -- Timestamps -----------------------------------------------------
    created_at: datetime | None = None
    updated_at: datetime | None = None

    # -- Backend field filtering ----------------------------------------
    _db_include: set[str] | None = {
        "id", "statement_id", "tab_slug", "tab_name",
        "tab_url", "raw_html",
        "attachments", "crawl_time", "parse_time",
        "status", "error_message",
        "created_at", "updated_at",
    }
    _search_include: set[str] | None = set()
    _warehouse_include: set[str] | None = None
    _timestamps = {"created_at", "updated_at"}
