'use strict';
import { and } from 'drizzle-orm';
import { queryIndexes } from './types/db-types.js';
import { isAnyColumn, hasSymbolKey, isValidTableName } from './guards/db-type-guards.js';
import { convertFromCamelToPascalCase } from '../../fd-toolbox/strings/casing-converter.js';
import { createError } from '../../fd-toolbox/errors/errors.js';
import { dbErrorMessages } from './constants/db-constants.js';
import { getQueryConfig as getQueryConfig$1, dbWhere, createDynamicSelect } from './db-connection.js';
import { getOptionalPropertyValue } from '../../fd-toolbox/objects/property-value.js';
import { getDbSchema } from './db-schema.js';
import { toolboxErrorMessages } from '../../fd-toolbox/constants/toolbox-error-messages-constants.js';

var __defProp=Object['defineProperty'],__name=(_0xb23ec7,_0x305bae)=>__defProp(_0xb23ec7,'name',{'value':_0x305bae,'configurable':!![]});function getColumnsFromTable(_0x15f904){return Object['entries'](_0x15f904)['reduce']((_0xf31d86,[_0x39b0fc,_0x2ba1fa])=>{if(isAnyColumn(_0x2ba1fa))return {..._0xf31d86,[_0x39b0fc]:_0x2ba1fa};return _0xf31d86;},{});}__name(getColumnsFromTable,'getColumnsFromTable');function getTableColumn(_0x1783db,_0x514667){return getColumnsFromTable(_0x1783db)[_0x514667];}__name(getTableColumn,'getTableColumn');function compareTableByName(_0x37bc0a,_0x27bf1e){const _0x5432c4=queryIndexes['tableName'],_0x3e6e53=Object['getOwnPropertySymbols'](_0x37bc0a)['find'](_0x9a36c0=>_0x9a36c0['description']===_0x5432c4);if(!_0x3e6e53)throw createError(toolboxErrorMessages['symbolNotFound']['replace']('{0}',_0x5432c4));const _0x51694d=hasSymbolKey(_0x37bc0a,_0x3e6e53)?convertFromCamelToPascalCase(_0x37bc0a[_0x3e6e53]):void(-0x136c+-0x259*-0x9+-0x1b5),_0xa2bcd=hasSymbolKey(_0x27bf1e,_0x3e6e53)?convertFromCamelToPascalCase(_0x27bf1e[_0x3e6e53]):void(-0x1*-0x15c1+0x33c*0x3+-0x1f75);return _0x51694d===_0xa2bcd;}__name(compareTableByName,'compareTableByName');function ensureTableNameIsValid(_0x52914e){if(!isValidTableName(_0x52914e))throw createError(dbErrorMessages['tableNotFound']['replace']('{0}',_0x52914e));return _0x52914e;}__name(ensureTableNameIsValid,'ensureTableNameIsValid');function getTableByName(_0x2d9b71){const _0x8cffdf=ensureTableNameIsValid(_0x2d9b71),_0x529deb=getDbSchema();return getOptionalPropertyValue(_0x529deb,_0x8cffdf);}__name(getTableByName,'getTableByName');function applyFilterToQuery(_0x24edb5,_0x2ba2ee){const _0x23338e=getQueryConfig$1(_0x24edb5)['where'],_0x120e16=and(_0x2ba2ee,_0x23338e);_0x120e16&&dbWhere(_0x24edb5,_0x120e16);}__name(applyFilterToQuery,'applyFilterToQuery');function getQueryConfig(_0x1bab3f){return getQueryConfig$1(_0x1bab3f);}__name(getQueryConfig,'getQueryConfig');async function getQueryWithoutGlobalFilters(_0x3b7dab,_0x2dd244){const _0x3b6b72=createDynamicSelect(_0x3b7dab,_0x2dd244);return {'query':_0x3b6b72};}__name(getQueryWithoutGlobalFilters,'getQueryWithoutGlobalFilters');async function runQuery(_0x1d5e9f){const _0x430bbc=await _0x1d5e9f;return _0x430bbc;}__name(runQuery,'runQuery');

export { applyFilterToQuery, compareTableByName, ensureTableNameIsValid, getColumnsFromTable, getQueryConfig, getQueryWithoutGlobalFilters, getTableByName, getTableColumn, runQuery };
