from datetime import datetime from sqlalchemy import String, DateTime, ForeignKey, Text from sqlalchemy.orm import Mapped, mapped_column, relationship from app.core.database import Base class Game(Base): __tablename__ = "games" id: Mapped[int] = mapped_column(primary_key=True) marathon_id: Mapped[int] = mapped_column(ForeignKey("marathons.id", ondelete="CASCADE"), index=True) title: Mapped[str] = mapped_column(String(100), nullable=False) cover_path: Mapped[str | None] = mapped_column(String(500), nullable=True) download_url: Mapped[str] = mapped_column(Text, nullable=False) genre: Mapped[str | None] = mapped_column(String(50), nullable=True) added_by_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="SET NULL"), nullable=True) created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow) # Relationships marathon: Mapped["Marathon"] = relationship("Marathon", back_populates="games") added_by_user: Mapped["User"] = relationship("User", back_populates="added_games") challenges: Mapped[list["Challenge"]] = relationship( "Challenge", back_populates="game", cascade="all, delete-orphan" )