'use strict';
import { v4 } from 'uuid';
import { getRoleToPermissionsByRoleId, createRoleToPermissionDirectlyInDb } from '../fd/fd-toolbox-asp-net/models/roles/role-to-permission-db.js';
import { roleIds } from '../../common/auth/roles/role-ids.js';
import { permissionPackages, permissions } from '../../common/auth/permissions/permission-constants.js';
import { toolboxUserConstants } from '../../meta/constants/toolbox-users.js';
import { logError } from '../../../fd-toolbox/server/logging/logger.js';
import { getRoleToPermissionPackages, createRoleToPermissionPackage } from '../../meta/server/models/roles/role-to-permission-package-db.js';
import { getNow } from '../../../fd-toolbox/time/date-time.js';

var __defProp=Object['defineProperty'],__name=(_0x59ef92,_0x494708)=>__defProp(_0x59ef92,'name',{'value':_0x494708,'configurable':!![]});async function createAndSeedRoleToPackageIfNotExist(){const _0x1b3b40=new Map([[roleIds['adminRoleId'],[permissionPackages['generalId'],permissionPackages['adminId']]],[roleIds['userRoleId'],[permissionPackages['generalId']]],[roleIds['traineeRoleId'],[permissionPackages['generalId']]],[roleIds['superAdminRoleId'],[permissionPackages['superAdminId']]]]),_0x494b40=await getRoleToPermissionPackages();for(const [_0x176d86,_0x77c712]of _0x1b3b40){for(const _0x31275e of _0x77c712){const _0x223038=_0x494b40['some'](_0x36218c=>_0x36218c['roleId']===_0x176d86&&_0x36218c['permissionPackageId']===_0x31275e);!_0x223038&&await createRoleToPackage(_0x176d86,_0x31275e);}}}__name(createAndSeedRoleToPackageIfNotExist,'createAndSeedRoleToPackageIfNotExist');async function seedAdminRoleToPermission(){const _0x1eb7fa=[permissions['editOtherUserId'],permissions['manageSubscriptionsId'],permissions['approveProductId']];await createRoleToPermissionIfNotExist(roleIds['adminRoleId'],_0x1eb7fa);}__name(seedAdminRoleToPermission,'seedAdminRoleToPermission');async function createRoleToPackage(_0x35db11,_0x3c48e4){try{await createRoleToPermissionPackage({'id':v4(),'roleId':_0x35db11,'permissionPackageId':_0x3c48e4,'createdByUserId':toolboxUserConstants['workerBotId'],'modifiedByUserId':toolboxUserConstants['workerBotId'],'createdDate':getNow(),'modifiedDate':getNow()});}catch(_0x3a20f3){logError('Error\x20creating\x20payment\x20and\x20storing\x20in\x20DB:',_0x3a20f3);}}__name(createRoleToPackage,'createRoleToPackage');async function createRoleToPermissionIfNotExist(_0x140c42,_0x3683c5){const _0x1ed90f=await getRoleToPermissionsByRoleId(_0x140c42);for(const _0x57381a of _0x3683c5){!_0x1ed90f['some'](_0x3facfc=>_0x3facfc['permissionId']===_0x57381a)&&await createRoleToPermissionDirectlyInDb({'id':v4(),'roleId':_0x140c42,'permissionId':_0x57381a,'createdByUserId':toolboxUserConstants['workerBotId'],'modifiedByUserId':toolboxUserConstants['workerBotId'],'createdDate':getNow(),'modifiedDate':getNow()});}}__name(createRoleToPermissionIfNotExist,'createRoleToPermissionIfNotExist');

export { createAndSeedRoleToPackageIfNotExist, seedAdminRoleToPermission };
