'use strict';
import { getSortColumns, sort, offset, limit, select } from './odata-expression-operators.js';
import { getQuery } from '../../web/drizzle.js';
import { tryFilter } from './odata-filters.js';
import { getResourceMeta } from '../../services/metas.js';
import { prepareODataSelectOrExpandTree } from './odata-parsers.js';
import { filterODataSelectOrExpandTree, groupODataResults } from './odata.js';
import { execQuery } from '../../db/db.js';

var __defProp=Object['defineProperty'],__name=(_0xf7e44a,_0x16db5c)=>__defProp(_0xf7e44a,'name',{'value':_0x16db5c,'configurable':!![]});async function getWithOData(_0x4ff941,_0x4c837e,_0x5cbc4e){const _0x38c428=await getResourceMeta(_0x5cbc4e),_0x5135c5=prepareODataSelectOrExpandTree(_0x4c837e['selects']),_0x399536=prepareODataSelectOrExpandTree(_0x4c837e['expands']),_0x4a842c=await filterODataSelectOrExpandTree(_0x5cbc4e,_0x5135c5),_0xf1608c=await filterODataSelectOrExpandTree(_0x5cbc4e,_0x399536,!![]),_0xdebaa9=!!_0x4a842c['children']&&Object['keys'](_0x4a842c['children'])['length']>0x34b*-0x1+0x1*-0x397+0x6e2,_0x19eabe=!!_0xf1608c['children']&&Object['keys'](_0xf1608c['children'])['length']>-0x1*0x9eb+0x377*-0x2+0x13*0xe3;let {query:_0x5d9090}=await getInitialQuery(_0x4ff941,_0x4a842c,_0xf1608c,_0x38c428),_0x565703=_0x5d9090;const _0x435d29=await getSortColumns(_0x565703,_0x4ff941,_0x38c428,_0x4c837e['orderBys']);_0x435d29['length']!==0x972+0x2d6+-0xc48&&(_0x565703=sort(_0x565703,_0x435d29)['query']);if((_0x4c837e['filters']?.['length']??0x1676+-0x386+-0x12f0)>-0xb49*0x1+-0x1d2e+0x2877){const _0xd39ff=await tryFilter(_0x565703,_0x4c837e,_0x4ff941,_0x5cbc4e);_0x565703=_0xd39ff['query'];}if(_0x4c837e['skip']){const _0x40031e=await offset(_0x565703,_0x4ff941,_0x4c837e['skip'],_0x435d29,_0x38c428);_0x565703=_0x40031e['query'];}if(_0x4c837e['top']){const _0x2c193a=await limit(_0x565703,_0x4ff941,_0x4c837e['top'],_0x435d29,_0x38c428);_0x565703=_0x2c193a['query'];}const _0x5d3a19=await execQuery(_0x565703);if(_0xdebaa9||_0x19eabe){const _0x513e3c=_0xdebaa9?_0x4a842c:_0xf1608c,_0x34758f=groupODataResults(_0x5d3a19,_0x513e3c,_0x38c428);return _0x34758f;}return _0x5d3a19;}__name(getWithOData,'getWithOData');async function getInitialQuery(_0x5642c3,_0x13d080,_0x20a6b1,_0x5cd184){const _0x241efe=!!_0x13d080['children']&&Object['keys'](_0x13d080['children'])['length']>-0x35b*0x6+-0x1052+0x2474*0x1,_0x10fe8a=!!_0x20a6b1['children']&&Object['keys'](_0x20a6b1['children'])['length']>0x182c+0x17ff+-0x302b;let _0x290066;if(_0x241efe)_0x290066=await select(_0x5642c3,_0x13d080,_0x5cd184);else _0x10fe8a?_0x290066=await select(_0x5642c3,_0x20a6b1,_0x5cd184):_0x290066=await getQuery(_0x5642c3);return _0x290066;}__name(getInitialQuery,'getInitialQuery');

export { getWithOData };
