package dto

// CreateRoleRequest 创建角色请求
type CreateRoleRequest struct {
	RoleName string `json:"role_name" validate:"required,min=1,max=50" required:"true" minLength:"1" maxLength:"50" description:"角色名称"`
	RoleDesc string `json:"role_desc" validate:"omitempty,max=255" maxLength:"255" description:"角色描述"`
	RoleType int    `json:"role_type" validate:"required,min=1,max=2" required:"true" minimum:"1" maximum:"2" description:"角色类型 (1:平台角色, 2:客户角色)"`
}

// UpdateRoleRequest 更新角色请求
type UpdateRoleRequest struct {
	RoleName *string `json:"role_name" validate:"omitempty,min=1,max=50" minLength:"1" maxLength:"50" description:"角色名称"`
	RoleDesc *string `json:"role_desc" validate:"omitempty,max=255" maxLength:"255" description:"角色描述"`
	Status   *int    `json:"status" validate:"omitempty,min=0,max=1" minimum:"0" maximum:"1" description:"状态 (0:禁用, 1:启用)"`
}

// UpdateRoleParams 更新角色参数聚合
type UpdateRoleParams struct {
	IDReq
	UpdateRoleRequest
}

// RoleListRequest 角色列表查询请求
type RoleListRequest 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:"每页数量"`
	RoleName string `json:"role_name" query:"role_name" validate:"omitempty,max=50" maxLength:"50" description:"角色名称模糊查询"`
	RoleType *int   `json:"role_type" query:"role_type" validate:"omitempty,min=1,max=2" minimum:"1" maximum:"2" description:"角色类型 (1:平台角色, 2:客户角色)"`
	Status   *int   `json:"status" query:"status" validate:"omitempty,min=0,max=1" minimum:"0" maximum:"1" description:"状态 (0:禁用, 1:启用)"`
}

// RoleResponse 角色响应
type RoleResponse struct {
	ID                   uint   `json:"id" description:"角色ID"`
	RoleName             string `json:"role_name" description:"角色名称"`
	RoleDesc             string `json:"role_desc" description:"角色描述"`
	RoleType             int    `json:"role_type" description:"角色类型 (1:平台角色, 2:客户角色)"`
	Status               int    `json:"status" description:"状态 (0:禁用, 1:启用)"`
	DefaultCreditEnabled bool   `json:"default_credit_enabled" description:"是否启用新建代理默认信用；仅客户角色有效"`
	DefaultCreditLimit   int64  `json:"default_credit_limit" description:"新建代理默认信用额度（分）；仅影响未来新建店铺"`
	DefaultCreditScope   string `json:"default_credit_scope" description:"模板生效范围，固定为 new_shops_only"`
	Creator              uint   `json:"creator" description:"创建人ID"`
	Updater              uint   `json:"updater" description:"更新人ID"`
	CreatedAt            string `json:"created_at" description:"创建时间"`
	UpdatedAt            string `json:"updated_at" description:"更新时间"`
}

// UpdateRoleDefaultCreditRequest 更新角色默认信用模板请求。
type UpdateRoleDefaultCreditRequest struct {
	CreditEnabled *bool  `json:"credit_enabled" validate:"required" required:"true" description:"是否启用新建代理默认信用"`
	CreditLimit   *int64 `json:"credit_limit" validate:"required,min=0" required:"true" minimum:"0" description:"新建代理默认信用额度（分）；关闭时必须为0，开启时必须大于0"`
}

// UpdateRoleDefaultCreditParams 更新角色默认信用模板参数。
type UpdateRoleDefaultCreditParams struct {
	IDReq
	UpdateRoleDefaultCreditRequest
}

// RoleDefaultCreditResponse 角色默认信用模板响应。
type RoleDefaultCreditResponse struct {
	RoleID                 uint   `json:"role_id" description:"客户角色ID"`
	CreditEnabled          bool   `json:"credit_enabled" description:"是否启用新建代理默认信用"`
	CreditLimit            int64  `json:"credit_limit" description:"新建代理默认信用额度（分）"`
	Scope                  string `json:"scope" description:"模板生效范围，固定为 new_shops_only"`
	AffectsExistingWallets bool   `json:"affects_existing_wallets" description:"是否影响既有钱包，固定为 false"`
}

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

// AssignPermissionsRequest 分配权限请求
type AssignPermissionsRequest struct {
	PermIDs []uint `json:"perm_ids" validate:"required,min=1" required:"true" minItems:"1" description:"权限ID列表"`
}

// AssignPermissionsParams 分配权限参数聚合
type AssignPermissionsParams struct {
	IDReq
	AssignPermissionsRequest
}

// RemovePermissionParams 移除权限参数聚合
type RemovePermissionParams struct {
	RoleID uint `path:"role_id" required:"true" description:"角色ID"`
	PermID uint `path:"perm_id" required:"true" description:"权限ID"`
}

// BatchRemovePermissionsRequest 批量移除权限请求
type BatchRemovePermissionsRequest struct {
	PermIDs []uint `json:"perm_ids" validate:"required,min=1" required:"true" minItems:"1" description:"权限ID列表"`
}

// BatchRemovePermissionsParams 批量移除权限参数聚合
type BatchRemovePermissionsParams struct {
	RoleID uint `path:"role_id" required:"true" description:"角色ID"`
	BatchRemovePermissionsRequest
}

// UpdateRoleStatusRequest 更新角色状态请求
type UpdateRoleStatusRequest struct {
	Status *int `json:"status" validate:"required,min=0,max=1" description:"状态 (0:禁用, 1:启用)"`
}

// UpdateRoleStatusParams 更新角色状态参数聚合
type UpdateRoleStatusParams struct {
	IDReq
	UpdateRoleStatusRequest
}
