package dto

// CreateAccountRequest 创建账号请求
type CreateAccountRequest struct {
	Username     string `json:"username" validate:"required,min=3,max=50" required:"true" minLength:"3" maxLength:"50" description:"用户名"`
	Phone        string `json:"phone" validate:"required,len=11" required:"true" minLength:"11" maxLength:"11" description:"手机号"`
	Password     string `json:"password" validate:"required,min=8,max=32" required:"true" minLength:"8" maxLength:"32" description:"密码"`
	UserType     int    `json:"user_type" validate:"required,min=1,max=4" required:"true" minimum:"1" maximum:"4" description:"用户类型 (1:超级管理员, 2:平台用户, 3:代理账号, 4:企业账号)"`
	ShopID       *uint  `json:"shop_id" description:"关联店铺ID（代理账号必填）"`
	EnterpriseID *uint  `json:"enterprise_id" description:"关联企业ID（企业账号必填）"`
}

// UpdateAccountRequest 更新账号请求
type UpdateAccountRequest struct {
	Username *string `json:"username" validate:"omitempty,min=3,max=50" minLength:"3" maxLength:"50" description:"用户名"`
	Phone    *string `json:"phone" validate:"omitempty,len=11" minLength:"11" maxLength:"11" description:"手机号"`
	Password *string `json:"password" validate:"omitempty,min=8,max=32" minLength:"8" maxLength:"32" description:"密码"`
	Status   *int    `json:"status" validate:"omitempty,min=0,max=1" minimum:"0" maximum:"1" description:"状态 (0:禁用, 1:启用)"`
}

// AccountListRequest 账号列表查询请求
type AccountListRequest struct {
	Page         int    `json:"page" query:"page" validate:"omitempty,min=1" minimum:"1" description:"页码"`
	PageSize     int    `json:"page_size" query:"page_size" validate:"omitempty,min=1,max=100" minimum:"1" maximum:"100" description:"每页数量"`
	Username     string `json:"username" query:"username" validate:"omitempty,max=50" maxLength:"50" description:"用户名模糊查询"`
	Phone        string `json:"phone" query:"phone" validate:"omitempty,max=20" maxLength:"20" description:"手机号模糊查询"`
	UserType     *int   `json:"user_type" query:"user_type" validate:"omitempty,min=1,max=4" minimum:"1" maximum:"4" description:"用户类型 (1:超级管理员, 2:平台用户, 3:代理账号, 4:企业账号)"`
	Status       *int   `json:"status" query:"status" validate:"omitempty,min=0,max=1" minimum:"0" maximum:"1" description:"状态 (0:禁用, 1:启用)"`
	ShopID       *uint  `json:"shop_id" query:"shop_id" validate:"omitempty,min=1" minimum:"1" description:"店铺ID筛选"`
	EnterpriseID *uint  `json:"enterprise_id" query:"enterprise_id" validate:"omitempty,min=1" minimum:"1" description:"企业ID筛选"`
}

// AccountResponse 账号响应
type AccountResponse struct {
	ID             uint   `json:"id" description:"账号ID"`
	Username       string `json:"username" description:"用户名"`
	Phone          string `json:"phone" description:"手机号"`
	UserType       int    `json:"user_type" description:"用户类型 (1:超级管理员, 2:平台用户, 3:代理账号, 4:企业账号)"`
	ShopID         *uint  `json:"shop_id,omitempty" description:"关联店铺ID"`
	ShopName       string `json:"shop_name,omitempty" description:"店铺名称"`
	EnterpriseID   *uint  `json:"enterprise_id,omitempty" description:"关联企业ID"`
	EnterpriseName string `json:"enterprise_name,omitempty" description:"企业名称"`
	WeComCorpID    string `json:"wecom_corp_id" description:"已绑定的企业微信企业 ID"`
	WeComUserID    string `json:"wecom_userid" description:"已绑定的企业微信成员 userid"`
	WeComName      string `json:"wecom_name" description:"已绑定的企业微信成员姓名快照"`
	WeComBound     bool   `json:"wecom_bound" description:"是否已绑定企业微信成员"`
	Status         int    `json:"status" description:"状态 (0:禁用, 1:启用)"`
	StatusName     string `json:"status_name" description:"状态名称（中文）"`
	Creator        uint   `json:"creator" description:"创建人ID"`
	Updater        uint   `json:"updater" description:"更新人ID"`
	CreatedAt      string `json:"created_at" description:"创建时间"`
	UpdatedAt      string `json:"updated_at" description:"更新时间"`
}

// AssignRolesRequest 分配角色请求
// 支持传递空数组以清空账号的所有角色
type AssignRolesRequest struct {
	RoleIDs []uint `json:"role_ids" validate:"omitempty" description:"角色ID列表，传空数组可清空所有角色"`
}

// AccountPageResult 账号分页响应
type AccountPageResult struct {
	Items []AccountResponse `json:"items" description:"账号列表"`
	Total int64             `json:"total" description:"总记录数"`
	Page  int               `json:"page" description:"当前页码"`
	Size  int               `json:"size" description:"每页数量"`
}

// ========== 平台账号管理专用 DTO ==========

// UpdatePasswordRequest 修改密码请求
// 用于管理员重置密码场景，无需验证旧密码
type UpdatePasswordRequest struct {
	NewPassword string `json:"new_password" validate:"required,min=8,max=32" required:"true" minLength:"8" maxLength:"32" description:"新密码（8-32位）"`
}

// UpdateStatusRequest 状态切换请求
// 用于启用/禁用账号
type UpdateStatusRequest struct {
	Status int `json:"status" validate:"required,min=0,max=1" required:"true" minimum:"0" maximum:"1" description:"状态（0:禁用，1:启用）"`
}

// PlatformAccountListRequest 平台账号列表查询请求
// 自动筛选 user_type IN (1, 2) 的账号
type PlatformAccountListRequest struct {
	Page     int    `json:"page" query:"page" validate:"omitempty,min=1" minimum:"1" description:"页码"`
	PageSize int    `json:"page_size" query:"page_size" validate:"omitempty,min=1,max=100" minimum:"1" maximum:"100" description:"每页数量"`
	Username string `json:"username" query:"username" validate:"omitempty,max=50" maxLength:"50" description:"用户名模糊查询"`
	Phone    string `json:"phone" query:"phone" validate:"omitempty,max=20" maxLength:"20" description:"手机号模糊查询"`
	Status   *int   `json:"status" query:"status" validate:"omitempty,min=0,max=1" minimum:"0" maximum:"1" description:"状态 (0:禁用, 1:启用)"`
}

// UpdatePasswordParams 修改密码参数（用于 OpenAPI 生成）
type UpdatePasswordParams struct {
	IDReq
	UpdatePasswordRequest
}

// UpdateStatusParams 状态切换参数（用于 OpenAPI 生成）
type UpdateStatusParams struct {
	IDReq
	UpdateStatusRequest
}

// BindAccountWeComRequest 绑定系统账号与企业微信可见成员请求。
type BindAccountWeComRequest struct {
	ApplicationID uint   `json:"application_id" validate:"required,gt=0" minimum:"1" description:"企业微信应用配置 ID"`
	UserID        string `json:"userid" validate:"required,min=1,max=64" minLength:"1" maxLength:"64" description:"企业微信成员 userid"`
}

// BindAccountWeComParams 绑定系统账号与企业微信成员参数。
type BindAccountWeComParams struct {
	IDReq
	BindAccountWeComRequest
}
