"""
素材主表模型
============

空镜视频片段的元数据中心，一行代表一个素材。

素材直接挂载在三级分类（mjk_broll_categories.level=3）下，
匹配时通过 category_id 精确关联到具体场景分类。
"""

from sqlalchemy import BigInteger, ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column

from app.models.base import BaseModelBigInt


class BrollMaterial(BaseModelBigInt):
    """空镜素材主表"""

    __tablename__ = "mjk_broll_materials"

    category_id: Mapped[int] = mapped_column(
        BigInteger,
        ForeignKey("mjk_broll_categories.id"),
        nullable=False,
        comment="所属三级分类ID，关联 mjk_broll_categories",
    )

    title: Mapped[str] = mapped_column(
        String(256),
        nullable=False,
        comment="素材标题/文件名，运营后台识别用",
    )

    url: Mapped[str] = mapped_column(
        String(1024),
        nullable=False,
        comment="七牛云 CDN 访问地址，FFmpeg合成和前端播放直接使用",
    )

    duration: Mapped[float] = mapped_column(
        default=0,
        nullable=False,
        comment="视频时长（秒），FFmpeg probe 提取，入库时必须大于0",
    )

    usage_count: Mapped[int] = mapped_column(
        BigInteger,
        default=0,
        nullable=False,
        comment="累计使用次数，驱动加权随机算法",
    )

    status: Mapped[str] = mapped_column(
        String(16),
        default="active",
        nullable=False,
        comment="状态：active（可用）/ disabled（下架）/ deleted（软删除）",
    )
