package rbac

import (
	"hyapp-admin-server/internal/middleware"

	"github.com/gin-gonic/gin"
)

func RegisterRoutes(protected *gin.RouterGroup, h *Handler) {
	protected.GET("/permissions", middleware.RequireAnyPermission("permission:view", "role:permission", "role:manage"), h.ListPermissions)
	protected.POST("/permissions", middleware.RequirePermission("permission:create"), h.CreatePermission)
	protected.PATCH("/permissions/:id", middleware.RequirePermission("permission:update"), h.UpdatePermission)
	protected.DELETE("/permissions/:id", middleware.RequirePermission("permission:delete"), h.DeletePermission)
	protected.POST("/permissions/sync", middleware.RequirePermission("permission:sync"), h.SyncPermissions)

	protected.GET("/roles", middleware.RequirePermission("role:view"), h.ListRoles)
	protected.POST("/roles", middleware.RequireAnyPermission("role:create", "role:manage"), h.CreateRole)
	protected.PATCH("/roles/:id", middleware.RequireAnyPermission("role:update", "role:manage"), h.UpdateRole)
	protected.DELETE("/roles/:id", middleware.RequireAnyPermission("role:delete", "role:manage"), h.DeleteRole)
	protected.PUT("/roles/:id/permissions", middleware.RequireAnyPermission("role:permission", "role:manage"), h.ReplaceRolePermissions)
	protected.GET("/roles/:id/data-scopes", middleware.RequirePermission("role:data-scope"), h.GetRoleDataScopes)
	protected.PUT("/roles/:id/data-scopes", middleware.RequirePermission("role:data-scope"), h.ReplaceRoleDataScopes)
}
