from __future__ import annotations

from datetime import datetime

from sqlalchemy import BigInteger, String, Text, UniqueConstraint, func
from sqlalchemy.orm import Mapped, mapped_column

from supply_infra.db.base import Base


class MultiDemandVideoDetail(Base):
    """需求池关联视频详情表 — 存 vid 与 ODPS 最终选题 JSON。"""

    __tablename__ = "multi_demand_video_detail"
    __table_args__ = (UniqueConstraint("vid", name="uk_multi_demand_video_detail_vid"),)

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
    vid: Mapped[str] = mapped_column(String(64), nullable=False, comment="视频id")
    url1: Mapped[str | None] = mapped_column(
        String(1024),
        nullable=True,
        comment="解构URL1（dwd_topic_decode_result_di 表字段，与 vid 同级）",
    )
    url2: Mapped[str | None] = mapped_column(
        String(1024),
        nullable=True,
        comment="解构URL2（dwd_topic_decode_result_di 表字段，与 vid 同级）",
    )
    title: Mapped[str | None] = mapped_column(
        String(512), nullable=True, comment="视频标题（decode_result.target_post.title）"
    )
    final_topic_json: Mapped[str] = mapped_column(
        Text, nullable=False, comment="最终选题JSON"
    )
    inspiration_points_json: Mapped[str | None] = mapped_column(
        Text,
        nullable=True,
        comment="灵感点列表JSON（decode_result.灵感点，每项保留 点/点描述）",
    )
    purpose_points_json: Mapped[str | None] = mapped_column(
        Text,
        nullable=True,
        comment="目的点列表JSON（decode_result.目的点，每项保留 点/点描述）",
    )
    key_points_json: Mapped[str | None] = mapped_column(
        Text,
        nullable=True,
        comment="关键点列表JSON（decode_result.关键点，每项保留 点/点描述）",
    )
    create_time: Mapped[datetime] = mapped_column(
        nullable=False,
        server_default=func.now(),
        comment="创建时间",
    )
    update_time: Mapped[datetime] = mapped_column(
        nullable=False,
        server_default=func.now(),
        onupdate=func.now(),
        comment="更新时间",
    )
