'use strict';
import { isNullOrUndefined } from '../../../fd-toolbox/functions/value-checking-functions.js';
import { wellKnownMetaProps } from '../../../fd-toolbox-core/constants/meta-constants.js';
import { fetchResourceMetas } from '../meta-providers.js';
import { getObjectValues } from '../../../fd-toolbox/lib/utils.js';
import { oDataSeparators } from '../../../fd-toolbox/odata/odata-filter-constants.js';
import { oDataPropertySeparator } from '../../../fd-toolbox/odata/odata-constants.js';
import { jsBasicTypes } from '../../../base-repo/constants/basic-types.js';
import { getManyToManySecondResourceName } from '../relations/meta-relations.js';
import { relationTypes } from '../../../fd-toolbox/enums/enums.js';

var __defProp=Object['defineProperty'],__name=(_0x481224,_0x47f9f9)=>__defProp(_0x481224,'name',{'value':_0x47f9f9,'configurable':!![]});function getODataSelectIfExpandForDescription(_0x52ba12,_0x3b00b7){const _0x3731af=[];for(const _0x56e9f0 of getObjectValues(_0x52ba12['properties'])){isPropertyExpandForDescription(_0x56e9f0)&&(_0x56e9f0['relation']?.['type']===relationTypes['manyToMany']?addManyToManyRelationSelects(_0x56e9f0,_0x3731af,_0x3b00b7):addSimpleRelationSelects(_0x56e9f0,_0x3731af,_0x3b00b7));}return addPropertyName(_0x3731af,_0x52ba12),_0x3731af;}__name(getODataSelectIfExpandForDescription,'getODataSelectIfExpandForDescription');function isPropertyExpandForDescription(_0x17ca24){return !isNullOrUndefined(_0x17ca24['relation'])&&!!_0x17ca24['relation']['expandForDescription']&&!!_0x17ca24['relation']['descriptionPropertyNames'];}__name(isPropertyExpandForDescription,'isPropertyExpandForDescription');async function getRelatedResourcesMetasIfExpandForDescription(_0x1770c8){const _0x6b98cd=new Set();for(const _0x1728a4 of getObjectValues(_0x1770c8['properties'])){isPropertyExpandForDescription(_0x1728a4)&&_0x1728a4['relation']?.['relatedResourceName']&&_0x6b98cd['add'](_0x1728a4['relation']['relatedResourceName']);if(_0x1728a4['relation']?.['type']===relationTypes['manyToMany']){const _0xe40251=getManyToManySecondResourceName(_0x1770c8['resourceName'],_0x1728a4);_0xe40251&&_0x6b98cd['add'](_0xe40251);}}const _0x4f4172=await fetchResourceMetas(Array['from'](_0x6b98cd));return getObjectValues(_0x4f4172);}__name(getRelatedResourcesMetasIfExpandForDescription,'getRelatedResourcesMetasIfExpandForDescription');function createSelectsArray(_0x4d2933=[],_0x226c97=[],_0x30d534=oDataSeparators['propertySeparator']){const _0x57ca4a=_0x226c97['flatMap'](({parent:_0x4478b9,children:_0x5d1157})=>_0x5d1157['map'](_0x5015f9=>''+_0x4478b9+_0x30d534+_0x5015f9));return [..._0x4d2933,..._0x57ca4a];}__name(createSelectsArray,'createSelectsArray');function addPropertyName(_0x31c244,_0x6a59d5){if(_0x31c244['length']>-0xf3b*-0x1+-0x739*0x5+-0x16*-0xf3)for(let _0xbea968 of getObjectValues(_0x6a59d5['properties'])){!_0xbea968['relation']?.['isExpandProperty']&&!_0x31c244['includes'](_0xbea968['name'])&&_0x31c244['push'](_0xbea968['name']);}}__name(addPropertyName,'addPropertyName');function addSimpleRelationSelects(_0x44c251,_0x35f09b,_0x230f3a){const _0xcaf5e7=_0x44c251['relation']?.['expandPropertyName'],_0x5a94a0=[_0x44c251['relation']?.['relatedPropertyName'],..._0x44c251['relation']['descriptionPropertyNames']],_0x2b0991=_0x230f3a['find'](_0x78a563=>_0x78a563['resourceName']===_0x44c251['relation']?.['relatedResourceName']);_0x2b0991?.['description']['useImage']&&_0x5a94a0['push'](wellKnownMetaProps['imageUrl']);for(const _0x5f1ad6 of _0x5a94a0){const _0x26998c=_0xcaf5e7+oDataPropertySeparator+_0x5f1ad6;if(!_0x35f09b['includes'](_0x26998c))_0x35f09b['push'](_0x26998c);}}__name(addSimpleRelationSelects,'addSimpleRelationSelects');function addManyToManyRelationSelects(_0x4600e0,_0x32dcfc,_0x1cab78){const _0x6eaa1a=_0x1cab78['find'](_0x200846=>_0x200846['resourceName']===_0x4600e0['relation']?.['manyToManyInfo']?.['firstResourceName']||_0x200846['resourceName']===_0x4600e0['relation']?.['manyToManyInfo']?.['secondResourceName']),_0x1cefd9=_0x6eaa1a?.['description']['resourceDescriptionProperty'],_0x54fc4a=_0x4600e0['relation']?.['expandPropertyName']+oDataPropertySeparator+_0x4600e0['relation']?.['manyToManyInfo']?.['secondExpandPropertyName']+oDataPropertySeparator+_0x1cefd9;!_0x32dcfc['includes'](_0x54fc4a)&&!_0x54fc4a['includes'](jsBasicTypes['undefined'])&&_0x32dcfc['push'](_0x54fc4a);}__name(addManyToManyRelationSelects,'addManyToManyRelationSelects');

export { createSelectsArray, getODataSelectIfExpandForDescription, getRelatedResourcesMetasIfExpandForDescription, isPropertyExpandForDescription };
