from datetime import datetime from sqlalchemy import ForeignKey, Index, Integer, String, DateTime from sqlalchemy.orm import Mapped, mapped_column from app.models.base import Base, SoftDeleteMixin, TimestampMixin class TeamInvitation(Base, TimestampMixin, SoftDeleteMixin): __tablename__ = "team_invitations" __table_args__ = ( Index("ix_team_invitations_team", "team_id", "status"), ) id: Mapped[str] = mapped_column(String(32), primary_key=True) team_id: Mapped[str] = mapped_column(String(32), ForeignKey("teams.id"), index=True, nullable=False) code: Mapped[str] = mapped_column(String(64), unique=True, index=True, nullable=False) created_by: Mapped[str] = mapped_column(String(32), ForeignKey("users.id"), nullable=False) status: Mapped[str] = mapped_column(String(16), default="active", server_default="active", nullable=False) max_uses: Mapped[int | None] = mapped_column(Integer, nullable=True) use_count: Mapped[int] = mapped_column(Integer, default=0, server_default="0", nullable=False) expires_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)