from __future__ import annotations

from datetime import datetime

from repo_core.base.models import DomainModel


class CodalRequestLog(DomainModel):
    """Every HTTP request made during crawling — both Camoufox HTML fetches
    and aiohttp media downloads.

    Write-once, insert-only.  No updates.
    """

    id: str
    url: str                              # Request URL
    request_at: datetime | None = None     # When the request was made
    raw_html: str | None = None            # Response body (HTML pages) or None (media)
    sha256: str | None = None              # SHA-256 of the response body
    status_code: int | None = None         # HTTP status code
    duration_ms: int | None = None         # Request duration in milliseconds

    created_at: datetime | None = None
    updated_at: datetime | None = None

    _db_include: set[str] | None = {
        "id", "url", "request_at", "raw_html", "sha256",
        "status_code", "duration_ms", "created_at", "updated_at",
    }
    _search_include: set[str] | None = set()
    _warehouse_include: set[str] | None = None
    _timestamps = {"created_at", "updated_at"}
