'use strict';
import { getResourcesWithOData } from '../db/db.js';
import { getEmptyODataConfig } from '../api/odata/odata.js';
import { getInternalResourceMeta } from '../resources/internal-resource-meta.js';
import { dynamicImportResourceHandlers } from '../modules/dynamic-imports.js';
import { createError } from '../../../../fd-toolbox/errors/errors.js';
import { toolboxErrorMessages } from '../../../../fd-toolbox/constants/toolbox-error-messages-constants.js';
import { getDynamicPropertyHandler } from '../resources/dynamic-properties.js';
import { setObjectPropertyValue } from '../../../../fd-toolbox/objects/property-value.js';

var __defProp=Object['defineProperty'],__name=(_0x48e3bd,_0x5c64c5)=>__defProp(_0x48e3bd,'name',{'value':_0x5c64c5,'configurable':!![]});async function getOData(_0x57d8b4,_0x5fb353,_0x351f17){let _0x5e93de=_0x351f17;_0x5e93de??=getEmptyODataConfig(),_0x5e93de=addOrderByToConfig(_0x5e93de,_0x5fb353);const _0x3b360c=await getInternalResourceMeta(_0x57d8b4);(_0x3b360c['crudHandlers']?.['length']||_0x3b360c['dynamicMetaProviders']?.['length'])&&await dynamicImportResourceHandlers(_0x3b360c['name']);const _0xf6aa73=Object['values'](_0x3b360c['properties'])['filter'](_0x244ce2=>{if(!_0x244ce2['isDynamic']||!_0x5e93de['selects'])return ![];return _0x5e93de['selects']['some'](_0x12033b=>_0x12033b===_0x244ce2['name']||_0x12033b['startsWith'](_0x244ce2['name']+'/'));});_0x5e93de['selects']&&(_0x5e93de['selects']=_0x5e93de['selects']['filter'](_0x967cfa=>!_0xf6aa73['some'](_0x134649=>_0x967cfa===_0x134649['name']||_0x967cfa['startsWith'](_0x134649['name']+'/'))));const _0x4b93cf=await getResourcesWithOData(_0x57d8b4,_0x5e93de);for(const _0xdc428d of _0x4b93cf){for(const _0x153588 of _0xf6aa73){const _0x453511=getDynamicPropertyHandler(_0x57d8b4,_0x153588['name']);if(!_0x153588['name']||!_0x453511)throw createError(toolboxErrorMessages['dynamicHandlerError']['replace']('{0}',_0x153588['name']));setObjectPropertyValue(_0xdc428d,_0x153588['name'],_0x453511(_0xdc428d));}}return _0x4b93cf;}__name(getOData,'getOData');function addOrderByToConfig(_0x31505a,_0x1d909d){return !_0x31505a['orderBys']?.['length']&&_0x1d909d['length']&&(_0x31505a['orderBys']=_0x1d909d),_0x31505a;}__name(addOrderByToConfig,'addOrderByToConfig');

export { getOData };
