"""代理客户绑定表"""
from datetime import datetime

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

from app.models.base import BaseModel


class AgentCustomer(BaseModel):
    __tablename__ = "agent_customers"

    agent_user_id: Mapped[int] = mapped_column(
        BigInteger, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True,
        comment="代理用户ID",
    )
    customer_user_id: Mapped[int] = mapped_column(
        BigInteger, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, unique=True, index=True,
        comment="客户用户ID",
    )
    bind_source: Mapped[str] = mapped_column(
        String(32), default="invite_code", nullable=False,
        comment="绑定来源: invite_code / coupon / manual / aff_link",
    )
    bound_at: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), nullable=False, comment="绑定时间",
    )
    first_order_id: Mapped[int | None] = mapped_column(
        Integer, nullable=True, comment="首单订单ID",
    )
    status: Mapped[str] = mapped_column(
        String(16), default="active", nullable=False,
        comment="绑定状态: active / frozen / released",
    )
