1"""Game items as Battle.net describes them, and the items members wish for.
2
3``BattlenetItem`` rows are filled on first read and fetched again when Battle.net starts serving a newer data version
4(its static namespace, such as ``static-1.60.1_70399-forever-us``). ``ItemName`` (``directory.py``) is separate: the
5names the addon reports, which exist even for items Battle.net does not know.
6"""
7
8from datetime import datetime # SQLAlchemy resolves Mapped[] annotations at runtime
9
10from advanced_alchemy.base import UUIDAuditBase
11from advanced_alchemy.types import DateTimeUTC, JsonB
12from sqlalchemy import BigInteger, Boolean, ForeignKey, Integer, String, Text, UniqueConstraint
13from sqlalchemy.orm import Mapped, mapped_column
14
15
[docs]
16class BattlenetItem(UUIDAuditBase):
17 """One item from the Battle.net Item API, with the lines of its in-game tooltip."""
18
19 __tablename__ = "battlenet_item"
20 __table_args__ = {
21 "comment": "Battle.net item data, filled on first read and refreshed when its data version changes."
22 }
23
24 item_id: Mapped[int] = mapped_column(Integer, unique=True, index=True)
25 name: Mapped[str] = mapped_column(Text)
26 quality: Mapped[str] = mapped_column(String(20))
27 quality_name: Mapped[str] = mapped_column(Text)
28 item_class: Mapped[str] = mapped_column(Text)
29 item_subclass: Mapped[str] = mapped_column(Text)
30 inventory_type: Mapped[str] = mapped_column(String(30))
31 inventory_type_name: Mapped[str] = mapped_column(Text)
32 item_level: Mapped[int] = mapped_column(Integer)
33 required_level: Mapped[int] = mapped_column(Integer)
34 sell_price: Mapped[int] = mapped_column(Integer)
35 is_equippable: Mapped[bool] = mapped_column(Boolean)
36 icon_url: Mapped[str | None] = mapped_column(Text, default=None)
37 tooltip: Mapped[list] = mapped_column(JsonB, default=list)
38 data_version: Mapped[str] = mapped_column(Text)
39 fetched_at: Mapped[datetime] = mapped_column(DateTimeUTC(timezone=True))
40
41
[docs]
42class ItemWish(UUIDAuditBase):
43 """One item on a member's wishlist. Officers see who wants a drop; the loot rules don't change."""
44
45 __tablename__ = "item_wish"
46 __table_args__ = (
47 UniqueConstraint("member_id", "item_id", name="uq_item_wish_member_item"),
48 {"comment": "Items members want; officers see them next to loot points. Deleted with the member."},
49 )
50
51 member_id: Mapped[int] = mapped_column(BigInteger, ForeignKey("member.id", ondelete="CASCADE"), index=True)
52 item_id: Mapped[int] = mapped_column(Integer, index=True)
53 note: Mapped[str | None] = mapped_column(Text, default=None)