from sqlalchemy import Boolean, String, UniqueConstraint from sqlalchemy.orm import Mapped, mapped_column from app.core.db import Base from app.models.mixins import TimestampMixin, UUIDPrimaryKeyMixin ROLES = ("operations_manager", "rental_employee") class User(UUIDPrimaryKeyMixin, TimestampMixin, Base): __tablename__ = "users" __table_args__ = ( UniqueConstraint("identity_provider", "external_subject", name="uq_user_external_identity"), ) public_ref: Mapped[str] = mapped_column(String(20), unique=True, nullable=False) email: Mapped[str | None] = mapped_column(String(320), unique=True, nullable=True) password_hash: Mapped[str | None] = mapped_column(String(512), nullable=True) display_name: Mapped[str] = mapped_column(String(120), nullable=False) role: Mapped[str] = mapped_column(String(30), nullable=False) active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True) identity_provider: Mapped[str | None] = mapped_column(String(80), nullable=True) external_subject: Mapped[str | None] = mapped_column(String(255), nullable=True)