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

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


class UserOAuthApp(Base, TimestampMixin, SoftDeleteMixin):
    __tablename__ = "user_oauth_app"

    id: Mapped[str] = mapped_column(
        String(32), primary_key=True, comment="主键"
    )
    app_id: Mapped[str] = mapped_column(
        String(64), unique=True, nullable=False, index=True, comment="应用id"
    )
    secret: Mapped[str] = mapped_column(
        String(256), nullable=False, comment="应用密钥"
    )
    status: Mapped[int] = mapped_column(
        BigInteger, nullable=False, default=1, comment="状态,1=正常,2=禁用"
    )
    max_count: Mapped[int] = mapped_column(
        BigInteger, nullable=False, default=100, comment="应用最大可以授权多少个用户"
    )
    auth_url: Mapped[str] = mapped_column(
        String(256), nullable=True,  comment="应用授权链接"
    )
    company: Mapped[str] = mapped_column(
        String(256), nullable=True,  comment="应用归属公司名称"
    )
    open_type: Mapped[int] = mapped_column(
        BigInteger, nullable=False, index=True, comment="开户方式（1=千川，2=广告，3=本地推，4=星图，5=快手代理商，6=巨量星图，7=巨量服务单，8=腾讯服务单，9=腾讯营销K2，10=腾讯营销K3）"
    )
    create_by: Mapped[str | None] = mapped_column(
        String(32), nullable=True, comment="创建者"
    )