'use strict';
import { propertyTypes } from '../../properties/property-type.js';
import { createError } from '../../../../fd-toolbox/errors/errors.js';
import { metaErrorMessages } from '../../constants/meta-error-messages-constants.js';
import { hasPermission, hasPropertyPermissionAsync } from '../permission/permission-checker.js';
import { isObject } from '../../../../fd-toolbox/types/ensure-type.js';
import { metaQueryParams } from '../../../../fd-toolbox/constants/meta-query-params.js';
import { getObjectValues } from '../../../../fd-toolbox/lib/utils.js';

var __defProp=Object['defineProperty'],__name=(_0x5ef301,_0x47810f)=>__defProp(_0x5ef301,'name',{'value':_0x47810f,'configurable':!![]});function getDefault(_0x4f366b){let _0xef1492;switch(_0x4f366b){case propertyTypes['boolean']:_0xef1492=![];break;case propertyTypes['integer']:_0xef1492=-0x177+0x1c97+0xe0*-0x1f;break;case propertyTypes['number']:_0xef1492=0x1075+0x242*0xa+0x2709*-0x1;break;case propertyTypes['string']:_0xef1492='';break;default:_0xef1492=void(0x75*0x4f+-0x181d+-0xbfe);}return _0xef1492;}__name(getDefault,'getDefault');async function setDefaultPropertyValueIfNoPermission(_0x3e8923,_0x4bb0c0,_0x1710ec,_0x3d09ec){await applyPropertyPermissions(_0x3e8923,_0x4bb0c0,_0x1710ec,_0x3d09ec);}__name(setDefaultPropertyValueIfNoPermission,'setDefaultPropertyValueIfNoPermission');function setPropertyDefaultValue(_0x2cf2e0,_0x4d26e5){Object['defineProperty'](_0x2cf2e0,_0x4d26e5['name'],{'value':getDefault(_0x4d26e5['type']),'writable':!![],'enumerable':!![],'configurable':!![]});}__name(setPropertyDefaultValue,'setPropertyDefaultValue');async function applyPropertyPermissions(_0x197eff,_0x2ff73a,_0xa0241c,_0x58a3bf){if(!_0xa0241c)throw createError(metaErrorMessages['resourceIsNull']['replace']('{0}',_0x2ff73a['resourceName']));const _0x4e4739=_0x58a3bf&&_0x58a3bf['length']>0x334+-0x1162+0xe2e,_0x4d1388=Boolean(await hasPermission(_0x197eff)),_0x4bca46=_0x2ff73a['auth']['accessByUserId']&&isResourceOwnedByUser(_0xa0241c,_0x197eff);await processResourceProperties(_0x2ff73a,_0xa0241c,_0x197eff,_0x4d1388,!!_0x4bca46,!!_0x4e4739,_0x58a3bf);}__name(applyPropertyPermissions,'applyPropertyPermissions');async function processResourceProperties(_0x70d3ba,_0x1c0ff3,_0x3017c0,_0x3f85b3,_0x3e1159,_0x594ca6,_0x162730){for(const _0x48711b of getObjectValues(_0x70d3ba['properties'])){const _0x3a4e14=_0x3e1159&&_0x70d3ba['auth']['belowLevelAllowedCrudByUserId']['includes'](_0x3017c0['crudAction']),_0x4f6460=_0x3f85b3||_0x3a4e14||Boolean(await hasPropertyPermissionAsync(_0x48711b['id'],_0x3017c0)),_0x547478=_0x594ca6&&_0x162730['includes'](_0x48711b['name']),_0x4d6f33=!_0x4f6460||_0x594ca6&&!_0x547478;_0x4d6f33&&setPropertyDefaultValue(_0x1c0ff3,_0x48711b);}}__name(processResourceProperties,'processResourceProperties');const userId=metaQueryParams['userId'];function isResourceOwnedByUser(_0xa5bf04,_0x391c7d){return !!(_0xa5bf04&&_0x391c7d['resource']&&_0x391c7d['userId']&&isObject(_0xa5bf04)&&metaQueryParams['userId']in _0xa5bf04&&_0xa5bf04[userId]===_0x391c7d['userId']);}__name(isResourceOwnedByUser,'isResourceOwnedByUser');

export { getDefault, setDefaultPropertyValueIfNoPermission };
