from pydantic import BaseModel, Field

from app.schemas.common import NaiveDatetime


class UserOAuthAppCreate(BaseModel):
    app_id: str = Field(..., max_length=64, description="应用id")
    secret: str = Field(..., max_length=256, description="应用密钥")
    open_type: int = Field(
        ...,
        ge=1,
        le=10,
        description="开户方式（1=千川，2=广告，3=本地推，4=星图，5=快手代理商，6=巨量星图，7=巨量服务单，8=腾讯服务单，9=腾讯营销K2，10=腾讯营销K3）",
    )
    count: int = Field(100, ge=1, description="应用最大可以授权多少个用户")
    auth_url: str | None = Field(None, max_length=256, description="应用授权链接")
    company: str | None = Field(None, max_length=256, description="应用归属公司名称")


class UserOAuthAppUpdate(BaseModel):
    secret: str | None = Field(None, max_length=256, description="应用密钥")
    open_type: int | None = Field(
        None,
        ge=1,
        le=10,
        description="开户方式（1=千川，2=广告，3=本地推，4=星图，5=快手代理商，6=巨量星图，7=巨量服务单，8=腾讯服务单，9=腾讯营销K2，10=腾讯营销K3）",
    )
    status: int | None = Field(None, ge=1, le=2, description="应用状态（1=正常,2=禁用）")
    count: int | None = Field(None, ge=1, description="应用最大可以授权多少个用户")
    auth_url: str | None = Field(None, max_length=256, description="应用授权链接")
    company: str | None = Field(None, max_length=256, description="应用归属公司名称")


class UserOAuthAppOut(BaseModel):
    id: str = Field(..., description="主键")
    app_id: str = Field(..., description="应用id")
    secret: str = Field(..., description="应用密钥")
    status: int = Field(..., description="状态,1=正常,2=禁用")
    max_count: int = Field(..., description="应用最大可以授权多少个用户")
    open_type: int = Field(..., description="开户方式")
    auth_url: str | None = Field(None, description="应用授权链接")
    company: str | None = Field(None, description="应用归属公司名称")
    create_by: str | None = Field(None, description="创建者")
    created_at: NaiveDatetime = Field(..., description="创建时间")
    updated_at: NaiveDatetime = Field(..., description="更新时间")

    model_config = {"from_attributes": True}