from __future__ import annotations

from datetime import datetime

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

from supply_infra.db.base import Base


class MultiDemandPoolDi(Base):
    """策略需求天级表 — 从 ODPS dwd_multi_demand_pool_di 同步。"""

    __tablename__ = "multi_demand_pool_di"
    __table_args__ = (
        Index("idx_biz_dt", "biz_dt"),
        Index("idx_strategy_demand", "strategy", "demand_id"),
    )

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
    strategy: Mapped[str] = mapped_column(String(128), nullable=False, comment="策略")
    demand_id: Mapped[str] = mapped_column(String(128), nullable=False, comment="需求id")
    demand_name: Mapped[str] = mapped_column(String(256), nullable=False, comment="需求名称")
    weight: Mapped[float | None] = mapped_column(Float, nullable=True, comment="权重")
    type: Mapped[str | None] = mapped_column(String(64), nullable=True, comment="需求类型")
    video_count: Mapped[int | None] = mapped_column(BigInteger, nullable=True, comment="视频数量")
    video_list: Mapped[str | None] = mapped_column(Text, nullable=True, comment="视频列表")
    extend: Mapped[str | None] = mapped_column(Text, nullable=True, comment="拓展字段")
    real_rov_7d: Mapped[float | None] = mapped_column(
        Float, nullable=True, comment="近7日ROV相对全局diff(rov_diff)"
    )
    real_vov_7d: Mapped[float | None] = mapped_column(
        Float, nullable=True, comment="近7日VOV相对全局diff(vov_diff)"
    )
    biz_dt: Mapped[str] = mapped_column(String(32), nullable=False, comment="业务日期")
    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="更新时间",
    )
