tutor/tutor/models.py

124 lines
2.8 KiB
Python

import dataclasses
import datetime
import decimal
import enum
import typing
import uuid
class Color(enum.IntEnum):
Colorless = 0
White = 1
Blue = 2
Black = 3
Green = 4
Red = 5
def __str__(self) -> str:
colors: typing.Dict[int, str] = dict(zip(Color, "CWUBGR"))
return colors.get(self.value, "").replace("C", "")
@staticmethod
def to_string(colors: typing.Iterable["Color"]) -> str:
return "".join(map(str, sorted(colors)))
@staticmethod
def from_string(colors: str) -> typing.List["Color"]:
return [
color
for color in [dict(zip("CWUBGR", Color)).get(c) for c in colors.upper()]
if color is not None
]
class Rarity(enum.IntEnum):
Common = 1
Uncommon = 2
Rare = 3
Special = 4
Mythic = 5
Bonus = 6
def __str__(self):
return self.name.lower()
@staticmethod
def from_string(rarity: str) -> "Rarity":
try:
return {r.name: r for r in Rarity}[rarity.capitalize()]
except KeyError:
raise TypeError(f"Unknown rarity '{rarity}'")
class Game(enum.Enum):
Paper = "paper"
Arena = "arena"
MTGOnline = "mtgo"
class Legality(enum.Enum):
Legal = "legal"
NotLegal = "not_legal"
Restricted = "restricted"
Banned = "banned"
@dataclasses.dataclass
class OracleCard:
oracle_id: uuid.UUID
name: str
color_identity: typing.List[Color]
cmc: decimal.Decimal
type_line: str
games: typing.Set[Game]
legalities: typing.Dict[str, Legality]
mana_cost: typing.Optional[str] = None
edhrec_rank: typing.Optional[int] = None
oracle_text: typing.Optional[str] = None
@dataclasses.dataclass
class Card:
scryfall_id: uuid.UUID
oracle_id: uuid.UUID
name: str
set_code: str
set_name: str
collector_number: str
rarity: Rarity
color_identity: typing.List[Color]
cmc: decimal.Decimal
type_line: str
release_date: datetime.date
games: typing.Set[Game]
legalities: typing.Dict[str, Legality]
mana_cost: typing.Optional[str] = None
edhrec_rank: typing.Optional[int] = None
oracle_text: typing.Optional[str] = None
price_usd: typing.Optional[decimal.Decimal] = None
price_usd_foil: typing.Optional[decimal.Decimal] = None
price_eur: typing.Optional[decimal.Decimal] = None
price_eur_foil: typing.Optional[decimal.Decimal] = None
price_tix: typing.Optional[decimal.Decimal] = None
@dataclasses.dataclass
class CardCopy:
card: Card
foil: bool
language: str = "English"
collection: str = "Default"
condition: typing.Optional[str] = None
@dataclasses.dataclass
class DeckCard:
card: Card
quantity: int = 1
@dataclasses.dataclass
class Deck:
deck_id: int
name: str
cards: typing.List[DeckCard]