'use strict';
import { relationTypes } from '../../../fd-toolbox/enums/enums.js';
import { fetchResource } from '../resource-providers.js';
import { apiSetPropertyToUndefined } from '../edit-resource/services/property-metas.js';
import { withIdProps } from '../../../fd-toolbox-core/types/resource-with-id.js';
import { fetchUiResourceMeta } from '../ui-meta-providers.js';
import { emptyUuid } from '../../../fd-toolbox/constants/constants.js';

var __defProp=Object['defineProperty'],__name=(_0x3ddb84,_0x1ccb67)=>__defProp(_0x3ddb84,'name',{'value':_0x1ccb67,'configurable':!![]});function isOneToManyRelation(_0x26d335){return _0x26d335['relation']&&_0x26d335['relation']['type']===relationTypes['oneToMany'];}__name(isOneToManyRelation,'isOneToManyRelation');function isManyToOneRelation(_0x5c85cb){return _0x5c85cb['relation']&&_0x5c85cb['relation']['type']===relationTypes['manyToOne'];}__name(isManyToOneRelation,'isManyToOneRelation');async function removeResourceRelation(_0x525c37,_0x1f78e9,_0x8e4cfc,_0x9b6711,_0xb000c4,_0x557c8e){if(isOneToManyRelation(_0x8e4cfc['properties'][_0x9b6711])){const _0x33338e=_0x8e4cfc['properties'][_0x9b6711]['relation']['relatedPropertyName'];await unassignOneToMany(_0x525c37,_0x1f78e9,_0x33338e);}else isManyToOneRelation(_0x8e4cfc['properties'][_0x9b6711])&&(await unassignManyToOne(_0x557c8e,_0x9b6711,_0x8e4cfc['resourceName']),_0xb000c4());}__name(removeResourceRelation,'removeResourceRelation');function changeFiltersForManyToOne(_0x4a3fa9,_0x5e1420){for(const _0x158be2 in _0x4a3fa9){if(_0x4a3fa9[_0x158be2]['leftSide']===withIdProps['id'])_0x4a3fa9[_0x158be2]['rightSide']=_0x5e1420??void(-0x60d*-0x4+0xf*0x24f+-0x3ad5*0x1);}}__name(changeFiltersForManyToOne,'changeFiltersForManyToOne');async function getPropertyKeyByRelation(_0x2b6712,_0x1270df){const _0x13ce79=await fetchUiResourceMeta(_0x2b6712),_0x213e9e=_0x13ce79['resourceMeta']['properties'];for(const _0x221f0e of Object['keys'](_0x213e9e)){const _0x48678c=_0x213e9e[_0x221f0e];if(_0x48678c['relation']?.['relatedResourceName']===_0x1270df)return _0x221f0e;}return void(-0x1*0x246d+0x73b*0x1+0x1d32);}__name(getPropertyKeyByRelation,'getPropertyKeyByRelation');function getManyToManySecondResourceName(_0xbefaf1,_0x380970){let _0x30d4a4;return _0x380970['relation']?.['manyToManyInfo']&&(_0x30d4a4=_0xbefaf1===_0x380970['relation']['manyToManyInfo']['firstResourceName']?_0x380970['relation']['manyToManyInfo']['secondResourceName']:_0x380970['relation']['manyToManyInfo']['firstResourceName']),_0x30d4a4;}__name(getManyToManySecondResourceName,'getManyToManySecondResourceName');async function unassignManyToOne(_0x1c8db8,_0x2adce6,_0x41011f){await apiSetPropertyToUndefined(_0x1c8db8,_0x41011f,_0x2adce6);}__name(unassignManyToOne,'unassignManyToOne');async function unassignOneToMany(_0x54129e,_0x2ce888,_0x295a72){if(!_0x2ce888||_0x2ce888===emptyUuid)return;const _0x102f01=await fetchResource(_0x54129e,_0x2ce888);await apiSetPropertyToUndefined(_0x102f01,_0x54129e['resourceName'],_0x295a72);}__name(unassignOneToMany,'unassignOneToMany');

export { changeFiltersForManyToOne, getManyToManySecondResourceName, getPropertyKeyByRelation, isManyToOneRelation, isOneToManyRelation, removeResourceRelation };
