import uuid

from sqlalchemy import ForeignKey, String
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import Mapped, mapped_column

from app.models.base import Base, PGUUID, TenantScopedMixin, TimestampMixin, UUIDPKMixin


class Release(UUIDPKMixin, TenantScopedMixin, TimestampMixin, Base):
    """A point-in-time snapshot of what's currently published/active across
    Workflows, Forms, Pages, Dashboards, and Menus (see app/crud/release.py
    for how `snapshot` is captured) — an audit trail of "what was live",
    not a rollback mechanism or a separate staging/prod environment."""

    __tablename__ = "releases"

    name: Mapped[str] = mapped_column(String(200), nullable=False)
    description: Mapped[str | None] = mapped_column(String(1000))
    snapshot: Mapped[dict] = mapped_column(JSONB, nullable=False, server_default="{}")
    created_by: Mapped[uuid.UUID | None] = mapped_column(PGUUID(as_uuid=True), ForeignKey("users.id"))
