"""migration_runs — the run-report table for the legacy transforms.

One row per transform run (05 step 2: every script logs source count,
written, skipped-with-reasons). The report JSON carries per-step counts,
warnings (e.g. judgment #22 stragglers), the per-legacy-table
reconciliation, and per-currency row counts (07 #21). Written OUTSIDE
the transform transaction so a failed/rolled-back run still leaves its
report behind.
"""

import uuid
from datetime import datetime

from sqlalchemy import Boolean, DateTime, Uuid, func
from sqlalchemy.orm import Mapped, mapped_column

from app.models.base import Base, PortableJSON


class MigrationRun(Base):
    __tablename__ = "migration_runs"

    id: Mapped[uuid.UUID] = mapped_column(Uuid(), primary_key=True, default=uuid.uuid4)
    started_at: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), server_default=func.now()
    )
    finished_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
    ok: Mapped[bool] = mapped_column(Boolean(), default=False)
    report: Mapped[dict] = mapped_column(PortableJSON, default=dict)
