"""Artwork as a first-class entity (section 10) — never a `poster_url` column on media tables, so provenance/licensing can be tracked per asset.""" from __future__ import annotations import uuid from sqlalchemy import Boolean, Float, ForeignKey, Index, Integer, String, Text from sqlalchemy.orm import Mapped, mapped_column, relationship from app.models.base import Base, TimestampMixin, UUIDPrimaryKeyMixin from app.models.enums import ArtworkType from app.models.provider import Provider class Artwork(Base, UUIDPrimaryKeyMixin, TimestampMixin): __tablename__ = "artwork" __table_args__ = ( Index("ix_artwork_entity", "entity_type", "entity_id", "artwork_type"), ) # Polymorphic target: "movie", "series", "season", "episode", "person", # "company", "collection". entity_type: Mapped[str] = mapped_column(String(30), nullable=False) entity_id: Mapped[uuid.UUID] = mapped_column(nullable=False) artwork_type: Mapped[ArtworkType] = mapped_column(nullable=False) language_code: Mapped[str | None] = mapped_column( ForeignKey("languages.code"), nullable=True ) width: Mapped[int | None] = mapped_column(Integer, nullable=True) height: Mapped[int | None] = mapped_column(Integer, nullable=True) aspect_ratio: Mapped[float | None] = mapped_column(Float, nullable=True) vote_average: Mapped[float | None] = mapped_column(Float, nullable=True) is_primary: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False) provider_id: Mapped[uuid.UUID] = mapped_column( ForeignKey("providers.id", ondelete="CASCADE"), nullable=False ) provider_asset_id: Mapped[str | None] = mapped_column(String(200), nullable=True) original_url: Mapped[str] = mapped_column(String(1000), nullable=False) local_path: Mapped[str | None] = mapped_column(String(1000), nullable=True) checksum: Mapped[str | None] = mapped_column(String(128), nullable=True) attribution: Mapped[str | None] = mapped_column(Text, nullable=True) license: Mapped[str | None] = mapped_column(Text, nullable=True) provider: Mapped[Provider] = relationship() __all__ = ["Artwork"]