"""Library resource ORM model.""" from __future__ import annotations from sqlalchemy import Enum, Integer, JSON, String, Text from sqlalchemy.orm import Mapped, mapped_column, relationship from app.domain.enums import LibraryResourceStatus, LibraryResourceType from app.infra.db.base import Base, TimestampMixin class LibraryResourceORM(TimestampMixin, Base): """Persisted library resource independent from order-generated assets.""" __tablename__ = "library_resources" id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) resource_type: Mapped[LibraryResourceType] = mapped_column( Enum(LibraryResourceType, native_enum=False), nullable=False, index=True, ) name: Mapped[str] = mapped_column(String(255), nullable=False) description: Mapped[str | None] = mapped_column(Text, nullable=True) tags: Mapped[list[str]] = mapped_column(JSON, nullable=False, default=list) status: Mapped[LibraryResourceStatus] = mapped_column( Enum(LibraryResourceStatus, native_enum=False), nullable=False, default=LibraryResourceStatus.ACTIVE, index=True, ) gender: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True) age_group: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True) pose_id: Mapped[int | None] = mapped_column(Integer, nullable=True) environment: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True) category: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True) cover_file_id: Mapped[int | None] = mapped_column(Integer, nullable=True) original_file_id: Mapped[int | None] = mapped_column(Integer, nullable=True) files = relationship( "LibraryResourceFileORM", back_populates="resource", lazy="selectin", cascade="all, delete-orphan", )