'use strict';
import { getResource, updateResource } from '../../meta/server/db/db.js';
import { resourceNames } from '../../../fd-toolbox/resources/resource-names.js';
import { isPlainObject } from '../../../fd-toolbox/lib/utils.js';
import { isNullOrUndefined } from '../../../fd-toolbox/functions/value-checking-functions.js';
import { leadToLeadGroupProps } from '../../common/leads/props/lead-to-lead-group-props.js';

var __defProp=Object['defineProperty'],__name=(_0x3dc90f,_0x5a4181)=>__defProp(_0x3dc90f,'name',{'value':_0x5a4181,'configurable':!![]});async function updateLeadGroupCount(_0x114a9f,_0x20cdd7){let _0x3c8359;const _0xf7e539=await getResource({'resourceName':resourceNames['leadGroup'],'id':_0x114a9f});if(!_0xf7e539)return _0x3c8359;const _0x5cc660=Number(_0xf7e539['count']??-0x94a+0x6ef+0x25b);return _0x3c8359=updateResource({..._0xf7e539,'count':_0x20cdd7?_0x5cc660+(0x10*0x254+0x5dd*-0x3+-0x13a8):_0x5cc660-(-0x14f1+0xc2*-0x22+0x2eb6)},resourceNames['leadGroup']),_0x3c8359;}__name(updateLeadGroupCount,'updateLeadGroupCount');function isLeadToLeadGroup(_0x3de526){return isPlainObject(_0x3de526)&&!isNullOrUndefined(_0x3de526)&&leadToLeadGroupProps['leadGroupId']in _0x3de526;}__name(isLeadToLeadGroup,'isLeadToLeadGroup');async function afterUpdate(_0x2784d8){const _0x2c9abe=_0x2784d8['modifiedResource'],_0x257275=_0x2784d8['originalResource'];if(isLeadToLeadGroup(_0x2c9abe)&&!_0x257275)await updateLeadGroupCount(_0x2c9abe['leadGroupId'],!![]);else isLeadToLeadGroup(_0x2c9abe)&&isLeadToLeadGroup(_0x257275)&&_0x257275['leadGroupId']!==_0x2c9abe['leadGroupId']&&await Promise['all']([updateLeadGroupCount(_0x2c9abe['leadGroupId'],!![]),updateLeadGroupCount(_0x257275['leadGroupId'],![])]);}__name(afterUpdate,'afterUpdate');async function preDelete(_0x4646ec){const _0x4e8034=_0x4646ec['deleteResource'];if(!isLeadToLeadGroup(_0x4e8034))return;await updateLeadGroupCount(_0x4e8034['leadGroupId'],![]);}__name(preDelete,'preDelete');

export { afterUpdate as afterUpdateLeadToLeadGroup, preDelete as preDeleteLeadToLeadGroup, updateLeadGroupCount };
