from __future__ import annotations

from datetime import datetime

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

from supply_infra.db.base import Base


class DemandBelongCategory(Base):
    """需求归属分类。"""

    __tablename__ = "demand_belong_category"
    __table_args__ = (UniqueConstraint("name", name="demand_belong_category_pk"),)

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
    name: Mapped[str | None] = mapped_column(String(256), nullable=True, comment="需求名称")
    category_id: Mapped[int] = mapped_column(BigInteger, nullable=False, comment="分类id")
    reason: Mapped[str | None] = mapped_column(Text, nullable=True, comment="原因")
    video_list: Mapped[str | None] = mapped_column(
        Text, nullable=True, comment="关联视频列表JSON（最多10个）"
    )
    is_delete: Mapped[int] = mapped_column(
        Integer, default=0, nullable=False, comment="是否删除 0-正常 1-删除"
    )
    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="更新时间",
    )
