'use strict';
import { getResourceMeta } from './metas.js';
import { checkSupportedCrudActions } from './crud-actions.js';
import { getPermissionCheckConfig } from './permission-check-config-provider.js';
import { fillOdataConfigForMany } from '../api/odata/odata-metas.js';
import { getResourcePermissionChecker } from '../auth/permissions/resource-permission-checker-provider.js';
import { checkBelowLevelIfNoPermission, filterOutIfNoPermission } from './resource-provider-permissions.js';
import { getCrudHandler } from '../basic-crud/resource-crud-handlers.js';
import { crudHandlerNames } from '../constants/crud-handler-types.js';
import { getOData } from '../repositories/odata-db.js';
import { setDefaultPropertyValueIfNoPermission } from './resource-provider-defaults.js';
import { checkExpandsPropertiesForAccess, preventExpandsIfHasNoAccess } from './resource-provider-expands.js';
import { getEmptyODataConfig } from '../api/odata/odata.js';
import { hasPermission } from '../permission/permission-checker.js';
import { getInternalResourceMeta } from '../resources/internal-resource-meta.js';
import { getResource } from '../db/db.js';
import { getResourceByIdWithConfig } from './resource-provider-db.js';
import { removeUndefinedValuesFromObject, removeOutsideExcludedProperties } from '../web/reduce-data.js';
import { ensureWithIndexer } from '../../../../fd-toolbox/types/ensure-type.js';
import { isWithId } from '../../../../fd-toolbox/lib/utils.js';
import { getUserId } from '../auth/users/current-user-id-provider.js';
import { crudActions } from '../../../../fd-toolbox/enums/enums.js';

var __defProp=Object['defineProperty'],__name=(_0x7054c2,_0x3d96a8)=>__defProp(_0x7054c2,'name',{'value':_0x3d96a8,'configurable':!![]});async function getResources(_0x320766,_0x316f68,_0x3618d9,_0x105bbc=!![]){const _0x50f3d1=_0x3618d9??getEmptyODataConfig(),_0x559e44=await getResourceMeta(_0x320766);checkSupportedCrudActions(_0x559e44,crudActions['view']);const _0x487a56=getPermissionCheckConfig(_0x316f68,_0x559e44),_0x25a052=await hasPermission(_0x487a56);await fillOdataConfigForMany(_0x559e44,_0x50f3d1);const _0x3ee3e6=await getResourcePermissionChecker(_0x559e44['resourceName']);checkBelowLevelIfNoPermission(_0x50f3d1,_0x316f68,_0x25a052,_0x487a56,_0x559e44,_0x3ee3e6);const _0x39bf2d=await getCrudHandler(_0x320766,crudHandlerNames['get']),_0xf6b1a8=_0x39bf2d?await _0x39bf2d(_0x50f3d1):await getOData(_0x559e44['resourceName'],_0x559e44['orderBys']??[],_0x50f3d1),_0x5875c4=await filterOutIfNoPermission(_0xf6b1a8,_0x25a052,_0x487a56,_0x316f68,_0x559e44,_0x50f3d1);for(const _0x5b4c3b of _0x5875c4){await setDefaultPropertyValueIfNoPermission(_0x487a56,_0x559e44,_0x5b4c3b);_0x50f3d1?.['expands']&&_0x50f3d1?.['expands']['length']>0xc04+0x5a3+-0x11a7&&await checkExpandsPropertiesForAccess(_0x50f3d1,_0x559e44,_0x316f68,_0x5b4c3b);if(_0x105bbc)await filterObjectByAllowedProperties(_0x5b4c3b,_0x559e44,_0x50f3d1);}return removeUndefinedValuesFromObject(_0x5875c4);}__name(getResources,'getResources');async function tryGetResourceById(_0x4577bc,_0x408941,_0x39213b,_0x4d890d=!![],_0x1a2aa1){const _0x1c1929=await getInternalResourceMeta(_0x4577bc),_0x42cbe5=_0x1c1929['name'],_0x3f333b=await getResourceMeta(_0x42cbe5),_0x4b3cc5=getPermissionCheckConfig(_0x39213b,_0x3f333b);checkSupportedCrudActions(_0x3f333b,crudActions['view']);let _0xf14426,_0x478d90;const _0x29243d=await getCrudHandler(_0x4577bc,crudHandlerNames['getOne']),_0x10197e=await getInternalResourceMeta(_0x3f333b['resourceName']);if(_0x1a2aa1)_0xf14426=await getResourceByIdWithConfig(_0x3f333b,_0x408941,_0x1a2aa1,_0x4d890d,_0x10197e,_0x29243d);else _0x29243d?_0xf14426=await _0x29243d(_0x408941,void(0x1d5*0xc+0x3b*0x6f+-0x2f91),_0x4d890d):_0xf14426=await getResource({'resourceName':_0x3f333b['resourceName'],'id':_0x408941},_0x4d890d);if(_0xf14426){_0x4b3cc5['resource']=_0xf14426;const _0x4082c7=await hasPermission(_0x4b3cc5);_0x4082c7&&(await setDefaultPropertyValueIfNoPermission(_0x4b3cc5,_0x3f333b,_0xf14426),_0x1a2aa1&&(_0xf14426=await preventExpandsIfHasNoAccess(_0x1a2aa1,_0x39213b,_0x3f333b,_0xf14426)),_0xf14426&&(await filterObjectByAllowedProperties(_0xf14426,_0x3f333b,_0x1a2aa1),_0x478d90=removeUndefinedValuesFromObject(_0xf14426)));}return _0x478d90;}__name(tryGetResourceById,'tryGetResourceById');async function getOneResource(_0x4f1c21){const _0x179d85=await getResourceMeta(_0x4f1c21['resourceName']);checkSupportedCrudActions(_0x179d85,crudActions['view']);const _0x2ae4f6=_0x4f1c21['userId']??await getUserId(),_0x44865b=await getResource(_0x4f1c21,!![]),_0x599bd4=getPermissionCheckConfig(_0x2ae4f6,_0x179d85,_0x44865b,crudActions['view'],!![]);return await hasPermission(_0x599bd4),await setDefaultPropertyValueIfNoPermission(_0x599bd4,_0x179d85,_0x44865b),removeUndefinedValuesFromObject(_0x44865b);}__name(getOneResource,'getOneResource');async function removeExcludedPropsFromExpanded(_0x35ed3f,_0x339ff7){for(const _0x97d34f of _0x35ed3f){const _0x17b9cb=ensureWithIndexer(_0x339ff7)[_0x97d34f];if(_0x17b9cb&&isWithId(_0x17b9cb)){const _0x2d20d2=await getResourceMeta(_0x97d34f);removeOutsideExcludedProperties(_0x17b9cb,_0x2d20d2);}}}__name(removeExcludedPropsFromExpanded,'removeExcludedPropsFromExpanded');async function filterObjectByAllowedProperties(_0x48603a,_0x845e1c,_0x1e9b50){const _0x17223c=_0x1e9b50?.['expands']??[];_0x17223c['length']>0x1*-0x239c+-0x1*0x150a+0x38a6&&await removeExcludedPropsFromExpanded(_0x17223c,_0x48603a),removeOutsideExcludedProperties(_0x48603a,_0x845e1c);}__name(filterObjectByAllowedProperties,'filterObjectByAllowedProperties');

export { getOneResource, getResources, tryGetResourceById };
