"""Invitation token model for user registration. Note: DateTime(timezone=True) is used for PostgreSQL compatibility. SQLite will store as naive UTC, which is handled in the repository layer. """ from datetime import datetime from typing import TYPE_CHECKING from sqlalchemy import Boolean, DateTime, Integer, String from sqlalchemy.orm import Mapped, mapped_column if TYPE_CHECKING: from sqlalchemy.orm import DeclarativeBase Base = DeclarativeBase else: from baby_monitor.repositories.dependencies.get_database import Base class Invitation(Base): """Invitation token for new user registration.""" __tablename__ = "invitations" id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) token: Mapped[str] = mapped_column(String, unique=True, nullable=False) created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), nullable=False ) expires_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), nullable=False ) created_by_user_id: Mapped[int] = mapped_column(Integer, nullable=False) is_consumed: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False) consumed_at: Mapped[datetime | None] = mapped_column( DateTime(timezone=True), nullable=True )