'use strict';
import { getTable, getResourcesWithOData } from '../../db/db.js';
import { createError } from '../../../../../fd-toolbox/errors/errors.js';
import { searchErrors, searchWarnings } from '../../../constants/search-constants.js';
import { getSearchableResources } from '../../resources/searchable-resources.js';
import { getResourceMeta } from '../../services/metas.js';
import { isResourceIdProperty, cutOffSuffix } from '../../props/property-names.js';
import { metas } from '../constants/metas.js';
import { logErrorRaw, logWarningRaw } from '../../../../../fd-toolbox/logging/loggers.js';
import { oDataLogicalOperationTypes, oDataComparisonTypes, oDataFilterTypes } from '../../../../../fd-toolbox/odata/odata-enums.js';
import { getObjectValues, isPromiseFulfilled } from '../../../../../fd-toolbox/lib/utils.js';

var __defProp=Object['defineProperty'],__name=(_0x19fd8f,_0x59da06)=>__defProp(_0x19fd8f,'name',{'value':_0x59da06,'configurable':!![]});async function searchAcrossResources(_0x27e683,_0xb8f08e){if(!_0x27e683)logErrorRaw(createError(searchErrors['searchQueryRequired']));const _0x57e686=[];for(const _0x42ef14 of _0xb8f08e){_0x57e686['push'](((async()=>{let _0x55a10c;const _0x135bbe=await getSearchableResources(),_0x133940=_0x135bbe['get'](_0x42ef14);if(!_0x133940||_0x133940['length']===0x1200+-0x5c5+-0xc3b)logWarningRaw(searchWarnings['noSearchableFieldsFoundResource']['replace']('{0}',_0x42ef14));else {const _0x4ce8e1=await getTable(_0x42ef14);if(!_0x4ce8e1)logWarningRaw(searchWarnings['noTableFoundResource']['replace']('{0}',_0x42ef14));else {const _0x4b8e1a=await getResourceMeta(_0x42ef14),_0x21cd2b=await Promise['all'](getObjectValues(_0x4b8e1a['properties'])['filter'](_0xcdd941=>!!_0xcdd941['relation']&&_0xcdd941['isListDisplayAdvisable'])['map'](async _0x12830a=>await isResourceIdProperty(_0x12830a['name'])?cutOffSuffix(_0x12830a['name'],metas['idSuffix']):_0x12830a['name'])),_0x37f155=[];for(const _0x26ca47 of _0x133940){_0x37f155['push']({'type':oDataFilterTypes['string'],'comparisonType':oDataComparisonTypes['includes'],'leftSide':_0x26ca47,'rightSide':_0x27e683,'logicalOperationType':oDataLogicalOperationTypes['or']});}const _0x18e555={'filters':_0x37f155,'orderBys':[],'expands':_0x21cd2b,'selects':[]},_0x4cc3da=await getResourcesWithOData(_0x42ef14,_0x18e555);_0x4cc3da['length']!==0x1*0x13f9+0x1*-0x136d+-0x8c&&(_0x55a10c={'resourceName':_0x42ef14,'resources':_0x4cc3da});}}return _0x55a10c;})()));}const _0x524afb=await Promise['allSettled'](_0x57e686),_0x144679=[];for(const _0x2d2c4c of _0x524afb){isPromiseFulfilled(_0x2d2c4c)&&_0x2d2c4c['value']&&_0x144679['push'](_0x2d2c4c['value']);}return _0x144679;}__name(searchAcrossResources,'searchAcrossResources');

export { searchAcrossResources };
