"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const db_1=require("@b/db"),query_1=require("@b/utils/query"),constants_1=require("@b/utils/constants");exports.metadata={summary:"Lists all permissions with pagination and optional filtering",operationId:"listPermissions",tags:["Admin","CRM","Permission"],parameters:constants_1.crudParameters,logModule:"ADMIN_CRM",logTitle:"List permissions",responses:{200:{description:"Paginated list of permissions with details",content:{"application/json":{schema:{type:"object",properties:{data:{type:"array",items:{type:"object",properties:{id:{type:"string",description:"ID of the permission"},name:{type:"string",description:"Name of the permission"},rolePermissions:{type:"array",description:"List of roles associated with the permission",items:{type:"object",properties:{roleId:{type:"string",description:"ID of the role"}}}}}}},pagination:constants_1.paginationSchema}}}}},401:{description:"Unauthorized, admin permission required"},500:{description:"Internal server error"}},requiresAuth:!0,permission:"view.permission"};exports.default=async e=>{const{query:s,ctx:i}=e;null==i||i.step("Fetching permissions");const t=await(0,query_1.getFiltered)({model:db_1.models.permission,query:s,sortField:s.sortField||"name",includeModels:[{model:db_1.models.role,as:"roles",through:{attributes:[]}}],timestamps:!1});null==i||i.success("Permissions retrieved successfully");return t};