package dto

// JSON:API Role DTOs

type RoleAttributes struct {
	Name        string `json:"name" example:"admin"`
	Description string `json:"description,omitempty" example:"Full access to all resources."`
	CreatedBy   string `json:"created_by,omitempty" example:"018f3a5c-7a6f-7c2a-8d4a-4b5b1f6c8e9d"`
	CreatedAt   string `json:"created_at,omitempty" example:"2026-02-05T10:00:00Z"`
	UpdatedAt   string `json:"updated_at,omitempty" example:"2026-02-05T10:00:00Z"`
}

type RoleResource struct {
	Type        string               `json:"type" example:"role"`
	ID          string               `json:"id" example:"018f3a5c-7a6f-7c2a-8d4a-4b5b1f6c8e9d"`
	Attributes  RoleAttributes       `json:"attributes"`
	Permissions []PermissionResource `json:"permissions,omitempty"`
}

type RoleResponse struct {
	Data RoleResource `json:"data"`
}

type RoleListResponse struct {
	Data []RoleResource `json:"data"`
	Meta struct {
		PageNumber int   `json:"page_number" example:"1"`
		PageSize   int   `json:"page_size" example:"20"`
		Total      int64 `json:"total" example:"120"`
	} `json:"meta"`
}

type RoleDataTableResponse struct {
	Data []RoleResource `json:"data"`
	Meta struct {
		Draw            int   `json:"draw" example:"1"`
		RecordsTotal    int64 `json:"records_total" example:"120"`
		RecordsFiltered int64 `json:"records_filtered" example:"12"`
	} `json:"meta"`
}

type PermissionAttributes struct {
	Name        string `json:"name" example:"User Management"`
	Key         string `json:"key" example:"user.manage"`
	Description string `json:"description,omitempty" example:"Allows managing users."`
	RequiresPIN bool   `json:"requires_pin" example:"true"`
	CreatedAt   string `json:"created_at,omitempty" example:"2026-02-05T10:00:00Z"`
	UpdatedAt   string `json:"updated_at,omitempty" example:"2026-02-05T10:00:00Z"`
}

type PermissionResource struct {
	Type       string               `json:"type" example:"permission"`
	ID         string               `json:"id" example:"018f3a5c-7a6f-7c2a-8d4a-4b5b1f6c8e9d"`
	Attributes PermissionAttributes `json:"attributes"`
}

type PermissionListResponse struct {
	Data []PermissionResource `json:"data"`
	Meta struct {
		PageNumber int   `json:"page_number" example:"1"`
		PageSize   int   `json:"page_size" example:"20"`
		Total      int64 `json:"total" example:"120"`
	} `json:"meta"`
}

type PermissionGroupResource struct {
	Module      string               `json:"module" example:"dul"`
	ModuleLabel string               `json:"module_label" example:"DUL"`
	Permissions []PermissionResource `json:"permissions"`
}

type PermissionGroupedResponse struct {
	Data []PermissionGroupResource `json:"data"`
}

// Create
type RoleCreateAttributes struct {
	Name        string `json:"name" validate:"required" example:"admin"`
	Description string `json:"description,omitempty" example:"Full access to all resources."`
}

type RoleCreateData struct {
	Type       string               `json:"type" validate:"required,oneof=role_create role" example:"role_create"`
	Attributes RoleCreateAttributes `json:"attributes" validate:"required"`
}

type RoleCreateRequest struct {
	Data RoleCreateData `json:"data" validate:"required"`
}

// Update
type RoleUpdateAttributes struct {
	Name        *string `json:"name,omitempty" example:"admin"`
	Description *string `json:"description,omitempty" example:"Full access to all resources."`
}

type RoleUpdateData struct {
	Type       string               `json:"type" validate:"required,oneof=role_update role" example:"role_update"`
	ID         string               `json:"id" example:"018f3a5c-7a6f-7c2a-8d4a-4b5b1f6c8e9d"`
	Attributes RoleUpdateAttributes `json:"attributes" validate:"required"`
}

type RoleUpdateRequest struct {
	Data RoleUpdateData `json:"data" validate:"required"`
}

// Role-Permission
type RolePermissionAttributes struct {
	RoleID       string `json:"role_id" example:"018f3a5c-7a6f-7c2a-8d4a-4b5b1f6c8e9d"`
	PermissionID string `json:"permission_id" example:"018f3a5c-7a6f-7c2a-8d4a-4b5b1f6c8e9e"`
}

type RolePermissionResource struct {
	Type       string                   `json:"type" example:"role_permission"`
	ID         string                   `json:"id" example:"018f3a5c-7a6f-7c2a-8d4a-4b5b1f6c8e9f"`
	Attributes RolePermissionAttributes `json:"attributes"`
}

type RolePermissionResponse struct {
	Data RolePermissionResource `json:"data"`
}

type RolePermissionListResponse struct {
	Data []RolePermissionResource `json:"data"`
}

type RolePermissionAssignAttributes struct {
	PermissionID string `json:"permission_id" validate:"required" example:"018f3a5c-7a6f-7c2a-8d4a-4b5b1f6c8e9e"`
}

type RolePermissionAssignData struct {
	Type       string                         `json:"type" validate:"required,eq=role_permission" example:"role_permission"`
	Attributes RolePermissionAssignAttributes `json:"attributes" validate:"required"`
}

type RolePermissionAssignRequest struct {
	Data RolePermissionAssignData `json:"data" validate:"required"`
}

type RolePermissionBulkAttributes struct {
	PermissionIDs []string `json:"permission_ids" validate:"required" example:"[\"018f3a5c-7a6f-7c2a-8d4a-4b5b1f6c8e9e\",\"018f3a5c-7a6f-7c2a-8d4a-4b5b1f6c8e9f\"]"`
}

type RolePermissionAssignBulkData struct {
	Type       string                       `json:"type" validate:"required,eq=role_assign_permission_bulk" example:"role_assign_permission_bulk"`
	Attributes RolePermissionBulkAttributes `json:"attributes" validate:"required"`
}

type RolePermissionAssignBulkRequest struct {
	Data RolePermissionAssignBulkData `json:"data" validate:"required"`
}

type RolePermissionRemoveBulkData struct {
	Type       string                       `json:"type" validate:"required,eq=role_remove_permission_bulk" example:"role_remove_permission_bulk"`
	Attributes RolePermissionBulkAttributes `json:"attributes" validate:"required"`
}

type RolePermissionRemoveBulkRequest struct {
	Data RolePermissionRemoveBulkData `json:"data" validate:"required"`
}

type PermissionUpdateAttributes struct {
	RequiresPIN *bool `json:"requires_pin" validate:"required" example:"true"`
}

type PermissionUpdateData struct {
	Type       string                     `json:"type" validate:"required,oneof=permission_update permission" example:"permission_update"`
	ID         string                     `json:"id" example:"018f3a5c-7a6f-7c2a-8d4a-4b5b1f6c8e9d"`
	Attributes PermissionUpdateAttributes `json:"attributes" validate:"required"`
}

type PermissionUpdateRequest struct {
	Data PermissionUpdateData `json:"data" validate:"required"`
}
