from datetime import datetime

from sqlalchemy import String
from sqlalchemy.dialects.postgresql import CITEXT, TIMESTAMP
from sqlalchemy.orm import Mapped, mapped_column

from app.models.base import Base, TimestampMixin, UUIDPKMixin
from app.models.identity import account_status


class PlatformAdmin(UUIDPKMixin, TimestampMixin, Base):
    """A platform-wide Super Admin account — deliberately NOT
    TenantScopedMixin (no tenant_id, no Row-Level Security). See
    db/schema.sql's platform_admins table comment and
    app/core/database.py::get_admin_scoped_db for how this account type
    reaches tenant-scoped data without belonging to any tenant itself."""

    __tablename__ = "platform_admins"

    name: Mapped[str] = mapped_column(String(200), nullable=False)
    email: Mapped[str] = mapped_column(CITEXT, nullable=False, unique=True)
    password_hash: Mapped[str] = mapped_column(String(255), nullable=False)
    status: Mapped[str] = mapped_column(account_status, nullable=False, server_default="active")
    last_login_at: Mapped[datetime | None] = mapped_column(TIMESTAMP(timezone=True))
