'use strict';
import { metas } from '../../../meta/server/meta-core/constants/metas.js';
import { personProps } from '../../../common/dev/props/person-props.js';
import { withIdProps } from '../../../../fd-toolbox-core/types/resource-with-id.js';
import { setDynamicPropertyHandler } from '../../../meta/server/resources/dynamic-properties.js';
import { resourceNames } from '../../../../fd-toolbox/resources/resource-names.js';
import { getResourceMeta } from '../../../meta/server/services/metas.js';
import { getOData } from '../../../meta/server/repositories/odata-db.js';
import { getResource } from '../../../meta/server/db/db.js';
import { personTestSuffixes, personHandlerMessages } from './person-constants.js';
import { crudActions } from '../../../../fd-toolbox/enums/enums.js';
import { oDataComparisonTypes, oDataFilterTypes } from '../../../../fd-toolbox/odata/odata-enums.js';
import { first } from '../../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x264326,_0x237fce)=>__defProp(_0x264326,'name',{'value':_0x237fce,'configurable':!![]});function getDynamicUiMetaConfig(){const _0x4cf2a2={'properties':{[personProps['middleName']]:{'isListDisplayable':![]},[withIdProps['id']]:{'isEditDisplayable':!![]}}};return _0x4cf2a2;}__name(getDynamicUiMetaConfig,'getDynamicUiMetaConfig');function getDynamicMetaConfig(){const _0x5b66e6={'properties':{[personProps['lastName']]:{'priority':metas['defaultStartingPropertyPriority']},[withIdProps['id']]:{'isDisplayable':!![],'isOutsideEditable':!![]}},'auth':{'belowLevelAllowedCrudByUserId':[crudActions['create'],crudActions['view'],crudActions['update'],crudActions['delete']]},'allowedCrudActions':[crudActions['create'],crudActions['view'],crudActions['update'],crudActions['delete']]};return _0x5b66e6;}__name(getDynamicMetaConfig,'getDynamicMetaConfig');setDynamicPropertyHandler(resourceNames['person'],personProps['friendCount'],_0x3c3fec=>{const _0x447265=_0x3c3fec['friendList'];return Array['isArray'](_0x447265)?_0x447265['length']:0x126d*-0x1+-0x741*0x1+-0x19ae*-0x1;}),setDynamicPropertyHandler(resourceNames['person'],personProps['fullName'],_0xa5614c=>{return _0xa5614c['name']+'\x20'+_0xa5614c['lastName'];});function preCreate(_0x2e7c7f){_0x2e7c7f['createResource']?.['name']['includes'](personTestSuffixes['applyTestHandlersSuffix'])&&(_0x2e7c7f['createResource']['name']+=personTestSuffixes['changedPersonNameWithPreCreateHandlerSuffix'],_0x2e7c7f['createResource']?.['name']['includes'](personTestSuffixes['preventCrudActionsSuffix'])&&(_0x2e7c7f['crudServiceResult']['validationResult']=createFalseTestValidationResult(personHandlerMessages['preCreateMessage'])));}__name(preCreate,'preCreate');function preUpdate(_0x1a7af0){_0x1a7af0['modifiedResource']?.['name']['includes'](personTestSuffixes['applyTestHandlersSuffix'])&&(_0x1a7af0['modifiedResource']['name']+=personTestSuffixes['changedPersonNameWithPreUpdateHandlerSuffix']),_0x1a7af0['modifiedResource']?.['name']['includes'](personTestSuffixes['preventCrudActionsSuffix'])&&(_0x1a7af0['crudServiceResult']['validationResult']=createFalseTestValidationResult(personHandlerMessages['preUpdateMessage']));}__name(preUpdate,'preUpdate');function preDelete(_0x10db1a){if(_0x10db1a['deleteResource']?.['name']['includes'](personTestSuffixes['preventCrudActionsSuffix']))_0x10db1a['crudServiceResult']['validationResult']=createFalseTestValidationResult(personHandlerMessages['preDeleteMessage']);}__name(preDelete,'preDelete');function afterUpdate(_0x23ff7d){if(_0x23ff7d['modifiedResource']?.['name']['includes'](personTestSuffixes['applyTestHandlersSuffix']))_0x23ff7d['crudServiceResult']['validationResult']['details']['push'](createTestValidationResult(personHandlerMessages['afterUpdateMessage']));}__name(afterUpdate,'afterUpdate');function afterDelete(_0x58ea84){if(_0x58ea84['deleteResource']?.['name']['includes'](personTestSuffixes['applyTestHandlersSuffix']))_0x58ea84['crudServiceResult']['validationResult']['details']['push'](createTestValidationResult(personHandlerMessages['afterDeleteMessage']));}__name(afterDelete,'afterDelete');async function get(_0x33e71c){const _0x34ba4c=await getResourceMeta(resourceNames['person']),_0x1555b2=await getOData(_0x34ba4c['resourceName'],_0x34ba4c['orderBys']??[],_0x33e71c),_0x5f27d8=[];for(const _0x6b24c8 of _0x1555b2){let _0x469aca=_0x6b24c8;_0x6b24c8['name']?.['includes'](personTestSuffixes['applyTestHandlersSuffix'])&&(_0x469aca={..._0x6b24c8,'name':_0x6b24c8['name']+personTestSuffixes['changedPersonNameWithProviderHandlerSuffix']}),_0x5f27d8['push'](_0x469aca);}return _0x5f27d8;}__name(get,'get');async function getOne(_0x532a1c,_0x336ad1,_0x19989a=!![]){const _0x504377=await getResourceMeta(resourceNames['person']);let _0x339020;if(_0x336ad1){const _0x550f92=_0x336ad1['filters']??[];_0x550f92['push']({'leftSide':withIdProps['id'],'rightSide':_0x532a1c,'type':oDataFilterTypes['guid'],'comparisonType':oDataComparisonTypes['equal']}),_0x336ad1['filters']=_0x550f92;const _0x54d081=await getOData(_0x504377['resourceName'],_0x504377['orderBys']??[],_0x336ad1);_0x339020=first(_0x54d081);}else _0x339020=await getResource({'resourceName':_0x504377['resourceName'],'id':_0x532a1c},_0x19989a);if(_0x339020?.['name']?.['includes'](personTestSuffixes['applyTestHandlersSuffix']))return {..._0x339020,'name':_0x339020['name']+personTestSuffixes['changedPersonNameWithProviderHandlerSuffix']};return _0x339020;}__name(getOne,'getOne');function createFalseTestValidationResult(_0xcd7424){const _0x587ab7={'isValid':![],'details':[createTestValidationResult(_0xcd7424)]};return _0x587ab7;}__name(createFalseTestValidationResult,'createFalseTestValidationResult');function createTestValidationResult(_0x42f3a6){const _0x4ede37={'message':_0x42f3a6,'code':'','propertyName':personProps['name'],'userFriendlyMessage':_0x42f3a6['replaceAll']('_','\x20')};return _0x4ede37;}__name(createTestValidationResult,'createTestValidationResult');

export { afterDelete, afterUpdate, get, getDynamicMetaConfig, getDynamicUiMetaConfig, getOne, preCreate, preDelete, preUpdate };
