"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.rolesManager=void 0;const db_1=require("@b/db"),sequelize_1=require("sequelize"),console_1=require("@b/utils/console");class RolesManager{constructor(){this.roles=new Map;RolesManager.instance||(RolesManager.instance=this);return RolesManager.instance}async initialize(){await this.loadRoles()}async loadRoles(){try{if(!db_1.models.role||!db_1.models.permission){console_1.logger.debug("ROLES","Models not yet initialized, skipping role loading");return}(await db_1.models.role.findAll({include:{model:db_1.models.permission,as:"permissions",through:{attributes:[]}}})).forEach(e=>{this.roles.set(e.id,{name:e.name,permissions:e.permissions.map(e=>e.name)})})}catch(e){e instanceof sequelize_1.DatabaseError?console_1.logger.error("ROLES","Failed to load roles - table not found",e):console_1.logger.error("ROLES","Failed to load roles and permissions",e)}}}exports.rolesManager=new RolesManager;