from datetime import datetime
from typing import Optional

from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column

from app.models.base import Base, TimestampMixin, SoftDeleteMixin


class PreTestTemplate(Base, TimestampMixin, SoftDeleteMixin):
    __tablename__ = "pre_test_template"

    id: Mapped[str] = mapped_column(
        String(32), primary_key=True, comment="主键"
    )
    name: Mapped[str] = mapped_column(
        String(128), nullable=False, comment="模板名称"
    )
    user_id: Mapped[str] = mapped_column(
        String(32), nullable=False, index=True, comment="用户id"
    )
    note: Mapped[Optional[str]] = mapped_column(
        Text, nullable=True, comment="模板备注"
    )
    platform: Mapped[Optional[str]] = mapped_column(
        String(32), nullable=True, comment="投放平台（AD/QIANCHUAN/LOCAL）"
    )
    external_action: Mapped[Optional[str]] = mapped_column(
        String(64), nullable=True, comment="转化目标"
    )
    cpa_bid: Mapped[Optional[float]] = mapped_column(
        nullable=True, comment="目标转化成本：[1, 10000]"
    )
    audience_gender: Mapped[Optional[str]] = mapped_column(
        String(16), nullable=True, comment="性别（ALL/MALE/FEMALE）"
    )
    audience_age: Mapped[Optional[str]] = mapped_column(
        Text, nullable=True, comment="受众年龄，JSON数组, 格式：[ALL,18-23, 24-30, 31-40, 41-49, 50+]"
    )
    audience_region: Mapped[Optional[str]] = mapped_column(
        Text, nullable=True, comment="受众地区，JSON数组（二级行政区域code）"
    )
    audience_network: Mapped[Optional[str]] = mapped_column(
        Text, nullable=True, comment="网络类型，JSON数组, 格式：[ALL,5G,4G,3G,2G,WIFI]"
    )
    cus_name: Mapped[Optional[str]] = mapped_column(
        String(256), nullable=True, comment="客户主体名称"
    )
    pricing_type: Mapped[Optional[str]] = mapped_column(
        String(16), nullable=True, comment="出价类型（OCPC/CPA/OCPM）"
    )
    cost_cap: Mapped[Optional[bool]] = mapped_column(
        Boolean, nullable=True, comment="是否最优成本出价（仅AD支持）"
    )
    target_cost: Mapped[Optional[bool]] = mapped_column(
        Boolean, nullable=True, comment="是否稳定成本出价（仅AD支持）"
    )
    nobid: Mapped[Optional[bool]] = mapped_column(
        Boolean, nullable=True, comment="是否最大转化出价（仅AD支持）"
    )
    cpc_bid: Mapped[Optional[float]] = mapped_column(
        nullable=True, comment="目标点击成本：[1, 10000]"
    )
    budget: Mapped[Optional[float]] = mapped_column(
        nullable=True, comment="预算金额：[1, 10000]"
    )
    is_default: Mapped[Optional[bool]] = mapped_column(
        Boolean, nullable=True, comment="是否默认模板"
    )
