from __future__ import annotations

from datetime import datetime

from repo_core.base.models import DomainModel


class CodalFile(DomainModel):
    """A downloaded attachment file stored in RustFS.

    One row per downloaded file (PDF, Excel, image).  Tracks RustFS
    location and download metadata.  Keyed by ``(statement_id, filename)``.
    """

    # -- Identity -------------------------------------------------------
    id: str
    statement_id: str
    filename: str

    # -- Source ---------------------------------------------------------
    url: str | None = None

    # -- File metadata --------------------------------------------------
    content_type: str | None = None
    size_bytes: int | None = None
    sha256: str | None = None

    # -- RustFS location ------------------------------------------------
    rustfs_bucket: str | None = None
    rustfs_key: str | None = None

    # -- Status ---------------------------------------------------------
    download_status: str = "pending"
    download_error: 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", "filename",
        "url", "content_type", "size_bytes", "sha256",
        "rustfs_bucket", "rustfs_key",
        "download_status", "download_error",
        "created_at", "updated_at",
    }
    _search_include: set[str] | None = set()
    _warehouse_include: set[str] | None = None
    _timestamps = {"created_at", "updated_at"}
