'use strict';
import { apiGetWithOData, apiGet } from '../../fd-toolbox/api/api-client.js';
import { getODataExpandIfExpandForDescription } from './odata/expands.js';
import { oDataDefaultTop } from '../../fd-toolbox/odata/odata-constants.js';
import { getRelatedResourcesMetasIfExpandForDescription, getODataSelectIfExpandForDescription } from './odata/odata-selects.js';
import { addPaging } from '../../fd-toolbox/odata/odataconfig.js';
import { isNullOrUndefined } from '../../fd-toolbox/functions/value-checking-functions.js';
import { fetchResourceMeta } from './meta-providers.js';

var __defProp=Object['defineProperty'],__name=(_0x4aaeb2,_0x3c6b4a)=>__defProp(_0x4aaeb2,'name',{'value':_0x3c6b4a,'configurable':!![]});async function fetchResources(_0x4667bd,_0x3cc305){const _0x39b660=await fetchResourceMeta(_0x4667bd),_0x1664b8=await getResourceODataConfig(_0x39b660,_0x3cc305);return (await apiGetWithOData(_0x4667bd,_0x1664b8))['data'];}__name(fetchResources,'fetchResources');async function fetchResource(_0x57c339,_0x4126d0,_0x2da4c5){let _0x2781ff,_0x2b9f6b;if(_0x2da4c5){const _0x590d45=await getResourceODataConfig(_0x57c339,_0x2da4c5);_0x2b9f6b=await apiGetWithOData(_0x57c339['resourceName'],_0x590d45,_0x4126d0);}else _0x2b9f6b=await apiGet(_0x57c339['resourceName'],_0x4126d0);if(_0x2b9f6b['data'])_0x2781ff=_0x2b9f6b['data'];return _0x2781ff;}__name(fetchResource,'fetchResource');async function getResourceODataConfig(_0x167703,_0x3b40a4){const _0x5b6f79=_0x3b40a4??{};if(!_0x5b6f79['expands']){const _0x1d85a7=await getRelatedResourcesMetasIfExpandForDescription(_0x167703);_0x5b6f79['selects']=Array['from'](new Set(getODataSelectIfExpandForDescription(_0x167703,_0x1d85a7)['concat'](_0x5b6f79['selects']??[]))),_0x5b6f79['expands']=getODataExpandIfExpandForDescription(_0x167703);}return isNullOrUndefined(_0x5b6f79['top'])&&addPaging(_0x5b6f79,oDataDefaultTop),_0x5b6f79;}__name(getResourceODataConfig,'getResourceODataConfig');async function fetchResourceByName(_0x20a629,_0x1ce794,_0xe5a8c7){let _0x48c381,_0x21840b;_0xe5a8c7?_0x21840b=await apiGetWithOData(_0x20a629,_0xe5a8c7,_0x1ce794):_0x21840b=await apiGet(_0x20a629,_0x1ce794);if(_0x21840b['data'])_0x48c381=_0x21840b['data'];return _0x48c381;}__name(fetchResourceByName,'fetchResourceByName');

export { fetchResource, fetchResourceByName, fetchResources, getResourceODataConfig };
