'use strict';
import { setCreatedByDateProperties } from '../../../../fd-toolbox/server/entities/base-objects.js';
import { getNow } from '../../../../fd-toolbox/time/date-time.js';
import { getInternalResourceMeta } from '../resources/internal-resource-meta.js';
import { isNonEmptyUuid, getNewUuid } from '../../../../fd-toolbox/uuids.js';
import { hasInternalPropertyMeta } from '../props/property-meta-config-provider.js';
import { getObjectValues } from '../../../../fd-toolbox/lib/utils.js';
import { createError } from '../../../../fd-toolbox/errors/errors.js';
import { toolboxErrorMessages } from '../../../../fd-toolbox/constants/toolbox-error-messages-constants.js';
import { baseResourceProps } from '../../../../fd-toolbox/base-resource/props/base-resource-props.js';

var __defProp=Object['defineProperty'],__name=(_0x4d144c,_0x43e102)=>__defProp(_0x4d144c,'name',{'value':_0x43e102,'configurable':!![]});function setModifiedProperties(_0x47bd51,_0x220457,_0x4be705){_0x4be705&&isBaseResource(_0x4be705)&&(_0x47bd51[baseResourceProps['modifiedDate']]=getNow(),_0x47bd51[baseResourceProps['modifiedByUserId']]=_0x220457);}__name(setModifiedProperties,'setModifiedProperties');async function prepareNewResource(_0x53f84c,_0x4c3455,_0x564719){!isNonEmptyUuid(_0x53f84c['id'])&&(_0x53f84c['id']=getNewUuid()),await setBaseResourceProperties(_0x53f84c,_0x4c3455,_0x564719);}__name(prepareNewResource,'prepareNewResource');async function setBaseResourceProperties(_0x3c7502,_0x29ca03,_0xe9871e){if(await hasInternalPropertyMeta(_0xe9871e,baseResourceProps['createdDate'])&&await hasInternalPropertyMeta(_0xe9871e,baseResourceProps['createdByUserId'])){!hasCreatedByDate(_0x3c7502)&&(_0x3c7502['createdDate']=getNow(),_0x3c7502['createdByUserId']=_0x29ca03);if(!hasCreatedByDate(_0x3c7502))throw createError(toolboxErrorMessages['resourceMissingCreatedByDateProperties']);await setCreatedByDateProperties(_0x3c7502,_0x29ca03);}const _0x278f61=await getInternalResourceMeta(_0xe9871e);isBaseResource(_0x278f61)&&(_0x3c7502['modifiedDate']=_0x3c7502['createdDate'],_0x3c7502['modifiedByUserId']=_0x3c7502['createdByUserId']);}__name(setBaseResourceProperties,'setBaseResourceProperties');function isBaseResource(_0x368310){const _0x325ec4=new Map(Object['entries'](_0x368310['properties']));return getObjectValues(baseResourceProps)['filter'](_0x100e77=>!_0x325ec4['has'](_0x100e77))['length']===0x20+-0x1ead+0x1e8d;}__name(isBaseResource,'isBaseResource');function hasCreatedByDate(_0x297719){return _0x297719['createdDate']!==void(-0x1*0xafd+0x11ef*-0x1+0x4d2*0x6)&&_0x297719['createdByUserId']!==void(-0x19d*-0x15+-0x1816+-0x9cb);}__name(hasCreatedByDate,'hasCreatedByDate');

export { isBaseResource, prepareNewResource, setBaseResourceProperties, setModifiedProperties };
