2026-02-08 11:16:13 +01:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
from sqlalchemy import DateTime, ForeignKey, SmallInteger, String, UniqueConstraint
|
|
|
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
|
|
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BossResult(Base):
|
|
|
|
|
__tablename__ = "boss_results"
|
|
|
|
|
__table_args__ = (
|
|
|
|
|
UniqueConstraint("run_id", "boss_battle_id", name="uq_boss_results_run_boss"),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
|
|
|
run_id: Mapped[int] = mapped_column(
|
|
|
|
|
ForeignKey("nuzlocke_runs.id", ondelete="CASCADE"), index=True
|
|
|
|
|
)
|
|
|
|
|
boss_battle_id: Mapped[int] = mapped_column(
|
|
|
|
|
ForeignKey("boss_battles.id"), index=True
|
|
|
|
|
)
|
|
|
|
|
result: Mapped[str] = mapped_column(String(10)) # won, lost
|
|
|
|
|
attempts: Mapped[int] = mapped_column(SmallInteger, default=1)
|
|
|
|
|
completed_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True))
|
|
|
|
|
|
2026-02-17 18:17:23 +01:00
|
|
|
run: Mapped[NuzlockeRun] = relationship(back_populates="boss_results")
|
|
|
|
|
boss_battle: Mapped[BossBattle] = relationship()
|
2026-03-20 21:41:38 +01:00
|
|
|
team: Mapped[list[BossResultTeam]] = relationship(
|
|
|
|
|
back_populates="boss_result", cascade="all, delete-orphan"
|
|
|
|
|
)
|
2026-02-08 11:16:13 +01:00
|
|
|
|
|
|
|
|
def __repr__(self) -> str:
|
2026-03-20 21:41:38 +01:00
|
|
|
return (
|
|
|
|
|
f"<BossResult(id={self.id}, run_id={self.run_id}, "
|
|
|
|
|
f"boss_battle_id={self.boss_battle_id}, result='{self.result}')>"
|
|
|
|
|
)
|