package routes

import (
	"github.com/gofiber/fiber/v2"

	"github.com/break/junhong_cmp_fiber/internal/handler/admin"
	"github.com/break/junhong_cmp_fiber/internal/model/dto"
	"github.com/break/junhong_cmp_fiber/pkg/openapi"
)

// registerPermissionRoutes 注册权限相关路由
func registerPermissionRoutes(api fiber.Router, h *admin.PermissionHandler, doc *openapi.Generator, basePath string) {
	permissions := api.Group("/permissions")
	groupPath := basePath + "/permissions"

	// 权限 CRUD
	Register(permissions, doc, groupPath, "POST", "", h.Create, RouteSpec{
		Summary: "创建权限",
		Tags:    []string{"权限"},
		Input:   new(dto.CreatePermissionRequest),
		Output:  new(dto.PermissionResponse),
		Auth:    true,
	})

	Register(permissions, doc, groupPath, "GET", "", h.List, RouteSpec{
		Summary: "权限列表",
		Tags:    []string{"权限"},
		Input:   new(dto.PermissionListRequest),
		Output:  new(dto.PermissionPageResult),
		Auth:    true,
	})

	Register(permissions, doc, groupPath, "GET", "/tree", h.GetTree, RouteSpec{
		Summary: "获取权限树",
		Tags:    []string{"权限"},
		Input:   new(dto.PermissionTreeRequest),
		Output:  new([]*dto.PermissionTreeNode),
		Auth:    true,
	})

	Register(permissions, doc, groupPath, "GET", "/:id", h.Get, RouteSpec{
		Summary: "获取权限详情",
		Tags:    []string{"权限"},
		Input:   new(dto.IDReq),
		Output:  new(dto.PermissionResponse),
		Auth:    true,
	})

	Register(permissions, doc, groupPath, "PUT", "/:id", h.Update, RouteSpec{
		Summary: "更新权限",
		Tags:    []string{"权限"},
		Input:   new(dto.UpdatePermissionParams),
		Output:  new(dto.PermissionResponse),
		Auth:    true,
	})

	Register(permissions, doc, groupPath, "DELETE", "/:id", h.Delete, RouteSpec{
		Summary: "删除权限",
		Tags:    []string{"权限"},
		Input:   new(dto.IDReq),
		Output:  nil,
		Auth:    true,
	})
}
