'use strict';
import { createError } from '../../../../../fd-toolbox/errors/errors.js';
import { getInternalResourceMeta } from '../../resources/internal-resource-meta.js';
import { getNewUuid } from '../../../../../fd-toolbox/uuids.js';
import { metaErrorMessages } from '../../../constants/meta-error-messages-constants.js';
import { getObjectValues } from '../../../../../fd-toolbox/lib/utils.js';
import { metaPropertyNames } from '../../constants/meta-property-names.js';
import { workspaceConstants } from '../../../../../fd-toolbox/server/constants/workspace-constants.js';
import { workspaceResourceProps } from '../../../multitenancy/props/workspace-resource-props.js';
import { setBaseResourceProperties } from '../../entities/edit-base-resources.js';

var __defProp=Object['defineProperty'],__name=(_0x2d6070,_0x2aaeb5)=>__defProp(_0x2d6070,'name',{'value':_0x2aaeb5,'configurable':!![]});async function prepareManyToManyResource(_0x1c3802,_0x2c0e62,_0x1e0574,_0x5a61f4,_0x3ceefb){const _0xe9fe4a=_0x5a61f4['relation']?.['manyToManyInfo'];if(!_0xe9fe4a)throw createError(metaErrorMessages['manyToManyInfoNotDefined']);const _0x542113=await getInternalResourceMeta(_0x1e0574['resourceName']),_0x3e39be=_0x542113['properties'][_0xe9fe4a['manyToManyFirstPropertyName']],_0x4b3c93=_0x542113['properties'][_0xe9fe4a['manyToManySecondPropertyName']];if(!_0x3e39be||!_0x4b3c93)throw createError(metaErrorMessages['manyToManyInternalPropertyNotDefined']);const _0x346448={'id':getNewUuid(0x1fa*0x2+0x1*-0x184a+0x145b,_0x1c3802['id'],_0x2c0e62),[_0x3e39be['name']]:_0x1c3802['id'],[_0x4b3c93['name']]:_0x2c0e62};await setBaseResourceProperties(_0x346448,_0x3ceefb,_0x1e0574['resourceName']);for(const _0x319c55 of getObjectValues(_0x1e0574['properties'])){_0x319c55['name']===metaPropertyNames['workspaceId']&&(_0x346448[workspaceResourceProps['workspaceId']]=workspaceConstants['defaultWorkspaceId']);}return _0x346448;}__name(prepareManyToManyResource,'prepareManyToManyResource');

export { prepareManyToManyResource };
