package usecase

import (
	"backend/pkg/permission/domain/permission"
	"context"
)

// PermissionUseCase 權限業務邏輯介面
type PermissionUseCase interface {
	// GetAll 取得所有權限
	GetAll(ctx context.Context) ([]*PermissionResponse, error)
	// GetTree 取得權限樹
	GetTree(ctx context.Context) (*PermissionTreeNode, error)
	// GetByHTTP 根據 HTTP 資訊取得權限
	GetByHTTP(ctx context.Context, path, method string) (*PermissionResponse, error)
	// ExpandPermissions 展開權限 (包含父權限)
	ExpandPermissions(ctx context.Context, permissions permission.Permissions) (permission.Permissions, error)
	// GetUsersByPermission 取得擁有指定權限的所有使用者
	GetUsersByPermission(ctx context.Context, permissionNames []string) ([]string, error)
}

// PermissionResponse 權限回應
type PermissionResponse struct {
	ID         string                 `json:"id"`
	ParentID   string                 `json:"parent_id"`
	Name       string                 `json:"name"`
	HTTPPath   string                 `json:"http_path,omitempty"`
	HTTPMethod string                 `json:"http_method,omitempty"`
	Status     permission.AccessState `json:"status"`
	Type       permission.Type        `json:"type"`
}

// PermissionTreeNode 權限樹節點
type PermissionTreeNode struct {
	*PermissionResponse
	Children []*PermissionTreeNode `json:"children,omitempty"`
}
