from sqlalchemy import ForeignKey, String from sqlalchemy.orm import Mapped, mapped_column from ttfrog.db.base import BaseObject, EnumField from ttfrog.db.schema.modifiers import ConditionMixin __all__ = [ "Item", "Spell", ] class ItemType(EnumField): ITEM = "ITEM" SPELL = "SPELL" SCROLL = "SCROLL" class Item(BaseObject, ConditionMixin): __tablename__ = "item" __mapper_args__ = { "polymorphic_identity": ItemType.ITEM, "polymorphic_on": "item_type" } id: Mapped[int] = mapped_column(init=False, primary_key=True, autoincrement=True) name: Mapped[str] = mapped_column(String(collation="NOCASE"), nullable=False, unique=True) consumable: Mapped[bool] = mapped_column(default=False) count: Mapped[int] = mapped_column(nullable=False, default=1) item_type: Mapped[ItemType] = mapped_column(default=ItemType.ITEM, nullable=False) class Spell(Item): __tablename__ = "spell" __mapper_args__ = { "polymorphic_identity": ItemType.SPELL } id: Mapped[int] = mapped_column(ForeignKey("item.id"), primary_key=True, init=False) level: Mapped[int] = mapped_column(nullable=False, info={"min": 0, "max": 9}, default=0) concentration: Mapped[bool] = mapped_column(default=False) item_type: Mapped[ItemType] = mapped_column(default=ItemType.SPELL, init=False)