'use strict';
import { getResourceNameOrDefault, isResourceIdProperty, cutOffSuffix, createResourceIdProperty } from '../props/property-names.js';
import { hasInternalResourceMeta, getInternalResourceMeta } from '../resources/internal-resource-meta.js';
import { metas } from '../meta-core/constants/metas.js';
import { isNullOrEmpty } from '../../../../fd-toolbox/server/strings/strings.js';
import { createManyToManyInfo } from '../../relations/many-to-many-info.js';
import { splitPascalCase, convertFromPascalToCamelCase } from '../../../../fd-toolbox/strings/casing-converter.js';
import { metaPropertyNames } from '../constants/meta-property-names.js';
import { getPropertyValue } from '../../../../fd-toolbox/objects/property-value.js';
import { first } from '../../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x2a8a74,_0x23bca4)=>__defProp(_0x2a8a74,'name',{'value':_0x23bca4,'configurable':!![]});async function isManyToManyResource(_0x28deb0,_0x47f94c=![]){let _0x441ec2=![],_0x22bf95;const _0x9db6ad=_0x28deb0&&_0x28deb0['includes'](metas['manyToManyConnector'])&&_0x28deb0['indexOf'](metas['manyToManyConnector'])<_0x28deb0['length']-metas['manyToManyConnector']['length'];if(_0x9db6ad)_0x22bf95=getManyToManyResourceNames(_0x28deb0);else await isManyToManyWithoutConnector(_0x28deb0)&&(_0x22bf95=await getNonConnectedManyToManyResourceNames(_0x28deb0));if(_0x22bf95){const _0x233ac1=await Promise['all'](_0x22bf95['map'](async _0x20ea8b=>!isNullOrEmpty(await getResourceNameOrDefault(_0x20ea8b)))),_0x3c237d=_0x22bf95['filter']((_0x389c7a,_0x21e52a)=>_0x233ac1[_0x21e52a]);_0x3c237d['length']===_0x22bf95['length']&&(!_0x47f94c||first(_0x3c237d)===_0x3c237d[0x1*-0x2047+-0x2153+-0xd1f*-0x5])&&(_0x441ec2=!![]);}return _0x441ec2;}__name(isManyToManyResource,'isManyToManyResource');function getManyToManyResourceNames(_0xd69fd8){return _0xd69fd8['split'](metas['manyToManyConnector']);}__name(getManyToManyResourceNames,'getManyToManyResourceNames');async function getNonConnectedManyToManyResourceNames(_0x2008c7){const _0x56e40b=splitPascalCase(_0x2008c7);for(let _0x4416ed=0x266e+0x1*-0x1eef+0x7*-0x112;_0x4416ed<_0x56e40b['length'];_0x4416ed++){const _0x3a1609=_0x56e40b['slice'](0xfd2+-0x66e+-0x964,_0x4416ed)['join'](''),_0x79eb08=_0x56e40b['slice'](_0x4416ed)['join']('');if(await hasInternalResourceMeta(_0x3a1609)&&await hasInternalResourceMeta(_0x79eb08))return [_0x3a1609,_0x79eb08];}return _0x56e40b;}__name(getNonConnectedManyToManyResourceNames,'getNonConnectedManyToManyResourceNames');async function isManyToManyWithoutConnector(_0x3b47cf){const _0x313491=await getNonConnectedManyToManyResourceNames(_0x3b47cf);if(_0x313491['length']===-0x1a5d+0x3*-0xfd+0x2*0xeab&&await hasInternalResourceMeta(first(_0x313491))&&await hasInternalResourceMeta(_0x313491[-0x1*0x2239+0xdf*0x16+-0xf10*-0x1])){const _0x5e9fbb=await getInternalResourceMeta(_0x3b47cf),_0x1272e2=_0x5e9fbb['properties'];if(_0x1272e2[convertFromPascalToCamelCase(first(_0x313491))+metaPropertyNames['idEndingConst']]&&_0x1272e2[convertFromPascalToCamelCase(_0x313491[0x1*0xa14+-0x16*-0x197+0x25f*-0x13])+metaPropertyNames['idEndingConst']])return !![];}return ![];}__name(isManyToManyWithoutConnector,'isManyToManyWithoutConnector');async function getManyToManyInfo(_0x3dba96,_0x4f9e31,_0x42c153){const _0x485dfa=createManyToManyInfo();let _0x408a4f=getManyToManyResourceNames(_0x3dba96['name']);_0x408a4f['length']<0x25cb*0x1+0x275*-0x7+-0x1496&&(_0x408a4f=await getNonConnectedManyToManyResourceNames(_0x3dba96['name']));const _0x20ea03=_0x42c153??first(_0x408a4f),_0x3770f5=[];for(const _0x4615fe of Object['keys'](_0x3dba96['properties'])){await isResourceIdProperty(_0x4615fe,_0x20ea03)&&_0x3770f5['push'](_0x4615fe);}_0x3770f5['sort']((_0x3463bc,_0xd70b4)=>_0x3463bc['localeCompare'](_0xd70b4));const _0x1b78df=_0x4f9e31??first(_0x3770f5);_0x485dfa['manyToManyResourceName']=_0x3dba96['name'],_0x485dfa['manyToManyFirstPropertyName']=_0x1b78df,_0x485dfa['isMirrorManyToManyResource']=await isManyToManyResource(_0x3dba96['name'],!![]),_0x485dfa['firstResourceName']=_0x20ea03??first(_0x408a4f);if(_0x485dfa['isMirrorManyToManyResource'])_0x485dfa['secondResourceName']=_0x408a4f[-0xb00+-0x1f71+0x2a72],_0x485dfa['manyToManySecondPropertyName']=_0x3770f5[-0x15ee+0x1979+-0x3*0x12e],_0x485dfa['firstExpandPropertyName']=cutOffSuffix(first(_0x3770f5),metas['idSuffix']),_0x485dfa['secondExpandPropertyName']=cutOffSuffix(_0x3770f5[-0x4d*-0x1c+-0xa51+0x1e6],metas['idSuffix']);else {const _0x337c4e=_0x408a4f['find'](_0x33092c=>_0x33092c!==_0x20ea03)??_0x408a4f[-0x1f38+0x3f*-0x90+0x1*0x42a9];_0x485dfa['secondResourceName']=_0x337c4e;let _0x1ca91b;for(const _0x4f4c38 of Object['keys'](_0x3dba96['properties'])){if(await isResourceIdProperty(_0x4f4c38,_0x337c4e)){_0x1ca91b=_0x4f4c38;break;}}_0x1ca91b??=createResourceIdProperty(_0x337c4e),_0x485dfa['manyToManySecondPropertyName']=_0x1ca91b,_0x485dfa['firstExpandPropertyName']=convertFromPascalToCamelCase(_0x20ea03),_0x485dfa['secondExpandPropertyName']=cutOffSuffix(_0x1ca91b,metas['idSuffix']);}return _0x485dfa;}__name(getManyToManyInfo,'getManyToManyInfo');function getManyToManySecondResourceId(_0x147d6a,_0x5301b8){return getPropertyValue(_0x147d6a,_0x5301b8['name']);}__name(getManyToManySecondResourceId,'getManyToManySecondResourceId');

export { getManyToManyInfo, getManyToManyResourceNames, getManyToManySecondResourceId, getNonConnectedManyToManyResourceNames, isManyToManyResource, isManyToManyWithoutConnector };
