package dto

// CreatePermissionRequest 创建权限请求
type CreatePermissionRequest struct {
	PermName string `json:"perm_name" validate:"required,min=1,max=50" required:"true" minLength:"1" maxLength:"50" description:"权限名称"`
	PermCode string `json:"perm_code" validate:"required,min=1,max=100" required:"true" minLength:"1" maxLength:"100" description:"权限编码"`
	PermType int    `json:"perm_type" validate:"required,min=1,max=2" required:"true" minimum:"1" maximum:"2" description:"权限类型 (1:菜单, 2:按钮)"`
	Platform string `json:"platform" validate:"omitempty,oneof=all web h5" description:"适用端口 (all:全部, web:Web后台, h5:H5端)，默认为 all"`
	URL      string `json:"url" validate:"omitempty,max=255" maxLength:"255" description:"请求路径"`
	ParentID *uint  `json:"parent_id" description:"父权限ID"`
	Sort     int    `json:"sort" validate:"omitempty,min=0" minimum:"0" description:"排序值"`
}

// UpdatePermissionRequest 更新权限请求
type UpdatePermissionRequest struct {
	PermName *string `json:"perm_name" validate:"omitempty,min=1,max=50" minLength:"1" maxLength:"50" description:"权限名称"`
	PermCode *string `json:"perm_code" validate:"omitempty,min=1,max=100" minLength:"1" maxLength:"100" description:"权限编码"`
	Platform *string `json:"platform" validate:"omitempty,oneof=all web h5" description:"适用端口 (all:全部, web:Web后台, h5:H5端)"`
	URL      *string `json:"url" validate:"omitempty,max=255" maxLength:"255" description:"请求路径"`
	ParentID *uint   `json:"parent_id" description:"父权限ID"`
	Sort     *int    `json:"sort" validate:"omitempty,min=0" minimum:"0" description:"排序值"`
	Status   *int    `json:"status" validate:"omitempty,min=0,max=1" minimum:"0" maximum:"1" description:"状态 (0:禁用, 1:启用)"`
}

// UpdatePermissionParams 更新权限参数聚合
type UpdatePermissionParams struct {
	IDReq
	UpdatePermissionRequest
}

// PermissionListRequest 权限列表查询请求
type PermissionListRequest 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:"每页数量"`
	PermName             string `json:"perm_name" query:"perm_name" validate:"omitempty,max=50" maxLength:"50" description:"权限名称模糊查询"`
	PermCode             string `json:"perm_code" query:"perm_code" validate:"omitempty,max=100" maxLength:"100" description:"权限编码模糊查询"`
	PermType             *int   `json:"perm_type" query:"perm_type" validate:"omitempty,min=1,max=2" minimum:"1" maximum:"2" description:"权限类型 (1:菜单, 2:按钮)"`
	Platform             string `json:"platform" query:"platform" validate:"omitempty,oneof=all web h5" description:"适用端口 (all:全部, web:Web后台, h5:H5端)"`
	AvailableForRoleType *int   `json:"available_for_role_type" query:"available_for_role_type" validate:"omitempty,min=1,max=2" minimum:"1" maximum:"2" description:"可用角色类型 (1:平台角色, 2:客户角色)"`
	ParentID             *uint  `json:"parent_id" query:"parent_id" description:"父权限ID"`
	Status               *int   `json:"status" query:"status" validate:"omitempty,min=0,max=1" minimum:"0" maximum:"1" description:"状态 (0:禁用, 1:启用)"`
}

// PermissionResponse 权限响应
type PermissionResponse struct {
	ID                    uint   `json:"id" description:"权限ID"`
	PermName              string `json:"perm_name" description:"权限名称"`
	PermCode              string `json:"perm_code" description:"权限编码"`
	PermType              int    `json:"perm_type" description:"权限类型 (1:菜单, 2:按钮)"`
	Platform              string `json:"platform" description:"适用端口 (all:全部, web:Web后台, h5:H5端)"`
	AvailableForRoleTypes string `json:"available_for_role_types" description:"可用角色类型 (1:平台角色, 2:客户角色)"`
	URL                   string `json:"url,omitempty" description:"请求路径"`
	ParentID              *uint  `json:"parent_id,omitempty" description:"父权限ID"`
	Sort                  int    `json:"sort" description:"排序值"`
	Status                int    `json:"status" description:"状态 (0:禁用, 1:启用)"`
	Creator               uint   `json:"creator" description:"创建人ID"`
	Updater               uint   `json:"updater" description:"更新人ID"`
	CreatedAt             string `json:"created_at" description:"创建时间"`
	UpdatedAt             string `json:"updated_at" description:"更新时间"`
}

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

// PermissionTreeRequest 权限树查询请求
type PermissionTreeRequest struct {
	AvailableForRoleType *int `json:"available_for_role_type" query:"available_for_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:启用)"`
}

// PermissionTreeNode 权限树节点（用于层级展示）
type PermissionTreeNode struct {
	ID                    uint                  `json:"id" description:"权限ID"`
	PermName              string                `json:"perm_name" description:"权限名称"`
	PermCode              string                `json:"perm_code" description:"权限编码"`
	PermType              int                   `json:"perm_type" description:"权限类型 (1:菜单, 2:按钮)"`
	Platform              string                `json:"platform" description:"适用端口 (all:全部, web:Web后台, h5:H5端)"`
	AvailableForRoleTypes string                `json:"available_for_role_types" description:"可用角色类型 (1:平台角色, 2:客户角色)"`
	URL                   string                `json:"url,omitempty" description:"请求路径"`
	Sort                  int                   `json:"sort" description:"排序值"`
	Status                int                   `json:"status" description:"状态 (0:禁用, 1:启用)"`
	Children              []*PermissionTreeNode `json:"children,omitempty" description:"子权限列表"`
}
