"""AFF/推广链接点击记录表"""
from datetime import datetime

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

from app.models.base import BaseModel


class AffiliateClick(BaseModel):
    __tablename__ = "affiliate_clicks"

    aff_code: Mapped[str] = mapped_column(String(64), nullable=False, index=True, comment="AFF标识码/邀请码")
    agent_id: Mapped[int | None] = mapped_column(
        BigInteger, nullable=True, index=True, comment="关联代理用户ID",
    )
    landing_url: Mapped[str | None] = mapped_column(Text, nullable=True, comment="落地页URL")
    ip: Mapped[str | None] = mapped_column(String(64), nullable=True, comment="访问IP")
    user_agent: Mapped[str | None] = mapped_column(Text, nullable=True, comment="浏览器User-Agent")
    referer: Mapped[str | None] = mapped_column(Text, nullable=True, comment="HTTP Referer")
    utm_source: Mapped[str | None] = mapped_column(String(128), nullable=True)
    utm_medium: Mapped[str | None] = mapped_column(String(128), nullable=True)
    utm_campaign: Mapped[str | None] = mapped_column(String(128), nullable=True)
    utm_content: Mapped[str | None] = mapped_column(String(128), nullable=True)
    utm_term: Mapped[str | None] = mapped_column(String(128), nullable=True)
    registered_user_id: Mapped[int | None] = mapped_column(
        BigInteger, nullable=True, comment="由此点击注册的用户ID",
    )
    converted_at: Mapped[datetime | None] = mapped_column(
        DateTime(timezone=True), nullable=True, comment="转化时间（注册或下单）",
    )
