'use strict';
import { eq } from 'drizzle-orm';
import { resourceNames } from '../../../../../fd-toolbox/resources/resource-names.js';
import { getQuery } from '../../web/drizzle.js';
import { getTableColumn, runQuery } from '../../../../db/drizzle-queries.js';
import { getDbSchema } from '../../../../db/db-schema.js';
import { getOptionalPropertyValue } from '../../../../../fd-toolbox/objects/property-value.js';
import { schemaNames, columnNames } from '../../../../db/constants/schema-names.js';

var __defProp=Object['defineProperty'],__name=(_0x4c2d45,_0x2cafa6)=>__defProp(_0x4c2d45,'name',{'value':_0x2cafa6,'configurable':!![]});async function getAllIncludingUserToRoles(){const _0x5a35d8=getDbSchema(),_0x398438=_0x5a35d8[schemaNames['roleSchema']],_0x3fe803=_0x5a35d8[schemaNames['userRoleSchema']],_0x1a6510=_0x5a35d8[schemaNames['userSchema']],_0x1843bd=await getQuery(_0x398438),_0x4a6073=_0x1843bd['query']['leftJoin'](_0x3fe803,eq(getTableColumn(_0x3fe803,columnNames['roleId']),getTableColumn(_0x398438,columnNames['id'])))['leftJoin'](_0x1a6510,eq(getTableColumn(_0x3fe803,columnNames['userId']),getTableColumn(_0x1a6510,columnNames['id']))),_0x39cb08=await runQuery(_0x4a6073),_0x1016c9=new Map();for(const _0x5c3d46 of _0x39cb08){const _0x540244=getOptionalPropertyValue(_0x5c3d46,resourceNames['role']);if(_0x540244){const _0x455611=getOrCreateRole(_0x1016c9,_0x540244),_0xa24312=getOptionalPropertyValue(_0x5c3d46,resourceNames['userRole']),_0x268dbd=getOptionalPropertyValue(_0x5c3d46,resourceNames['user']);_0xa24312&&_0x268dbd&&_0x455611['userRoleList']?.['push']({..._0xa24312,'role':_0x455611,'user':_0x268dbd});}}return Array['from'](_0x1016c9['values']());}__name(getAllIncludingUserToRoles,'getAllIncludingUserToRoles');function getOrCreateRole(_0x24053a,_0x1881f1){return !_0x24053a['has'](_0x1881f1['id'])&&(_0x1881f1['userRoleList']=[],_0x24053a['set'](_0x1881f1['id'],_0x1881f1)),_0x24053a['get'](_0x1881f1['id']);}__name(getOrCreateRole,'getOrCreateRole');

export { getAllIncludingUserToRoles };
