'use strict';
import { createDynamicSelect, dbWhere, dbLimit } from '../../db/db-connection.js';
import { getTableColumn, runQuery } from '../../db/drizzle-queries.js';
import { resourceNames } from '../../../fd-toolbox/resources/resource-names.js';
import { eq } from 'drizzle-orm';
import { hasAnyResource, findResourceById, updateResource } from '../../meta/server/db/db.js';
import { getDbSchema } from '../../db/db-schema.js';
import { apiNotFoundError } from '../../../fd-toolbox/server/web/errors.js';
import { metaErrorMessages } from '../../meta/constants/meta-error-messages-constants.js';
import { createResource } from '../../meta/server/resources/crud-resources.js';
import { schemaNames, columnNames } from '../../db/constants/schema-names.js';
import { singleOrUndefined } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x15e5fd,_0x959f52)=>__defProp(_0x15e5fd,'name',{'value':_0x959f52,'configurable':!![]});async function getRoleByName(_0x2dfc90){const _0x56949e=getDbSchema(),_0x274412=_0x56949e[schemaNames['roleSchema']],_0x47c0cb=createDynamicSelect(_0x274412);dbWhere(_0x47c0cb,eq(getTableColumn(_0x274412,columnNames['name']),_0x2dfc90)),dbLimit(_0x47c0cb,0x4b*0x1b+0xf2*-0xf+0x646);const _0x59407c=await runQuery(_0x47c0cb),_0x5e1d97=singleOrUndefined(_0x59407c);if(!_0x5e1d97)throw apiNotFoundError(metaErrorMessages['roleNotFound']['replace']('{0}',_0x2dfc90));const _0x51b2ae={..._0x5e1d97};return _0x51b2ae;}__name(getRoleByName,'getRoleByName');async function isRoleExists(_0x1f53c3){const _0x137888=getDbSchema(),_0x210e75=_0x137888[schemaNames['roleSchema']],_0x38c638=createDynamicSelect(_0x210e75,{'id':getTableColumn(_0x210e75,columnNames['id'])});dbWhere(_0x38c638,eq(getTableColumn(_0x210e75,columnNames['name']),_0x1f53c3)),dbLimit(_0x38c638,-0x2*-0xaa1+0x3*0x161+0x1*-0x1964);const _0x84aee8=await runQuery(_0x38c638);return _0x84aee8['length']>-0x56*0xd+0x17b*0x9+0x1*-0x8f5;}__name(isRoleExists,'isRoleExists');async function anyRoleExists(){const _0x5673c5=hasAnyResource(resourceNames['role']);return _0x5673c5;}__name(anyRoleExists,'anyRoleExists');async function upsertRole(_0x2c74af){const _0x202ea5=await findResourceById(resourceNames['role'],_0x2c74af['id']);_0x202ea5?await updateResource(_0x2c74af,resourceNames['role']):await createResource(_0x2c74af,resourceNames['role']);}__name(upsertRole,'upsertRole');

export { anyRoleExists, getRoleByName, isRoleExists, upsertRole };
