'use strict';
import { resourceNames } from '../../../fd-toolbox/resources/resource-names.js';
import { getResource } from '../../meta/server/db/db.js';
import { createStripeProductPricing, deactivateStripeProductPricing } from './stripe/stripes.js';
import { createError } from '../../../fd-toolbox/errors/errors.js';
import { paymentErrorMessages } from '../../common/payments/payment-constants.js';

var __defProp=Object['defineProperty'],__name=(_0x2cea5d,_0x4cd655)=>__defProp(_0x2cea5d,'name',{'value':_0x4cd655,'configurable':!![]});async function preUpdate(_0x278044){const _0x11154b=_0x278044['modifiedResource'],_0x439fe7=_0x278044['originalResource'],_0x10cd91=_0x278044['crudUpdateConfig'],_0x1f7f2b=await getResource({'resourceName':resourceNames['paymentPlan'],'id':_0x11154b['paymentPlanId']});if(_0x1f7f2b['paymentSystemId']){if(_0x10cd91['isCreate']){const _0x996791=await createStripeProductPricing(_0x1f7f2b['paymentSystemId'],_0x11154b['currency'],_0x11154b['price'],_0x11154b['id'],_0x11154b['billingInterval']);_0x11154b['paymentSystemPriceId']=_0x996791['id'];}else {const _0x401171=_0x11154b['currency'],_0x22912d=_0x439fe7?.['currency'],_0x47c9b6=_0x11154b['price'],_0x246766=_0x439fe7?.['price'];if(_0x401171!==_0x22912d||_0x47c9b6!==_0x246766)try{if(_0x439fe7?.['paymentSystemPriceId']){await deactivateStripeProductPricing(_0x439fe7['paymentSystemPriceId']);const _0x4f4514=await createStripeProductPricing(_0x1f7f2b['paymentSystemId'],_0x11154b['currency'],_0x11154b['price'],_0x11154b['id'],_0x11154b['billingInterval']);_0x11154b['paymentSystemPriceId']=_0x4f4514['id'];}}catch{createError(paymentErrorMessages['errorWhileEditingPrice']);}}}}__name(preUpdate,'preUpdate');async function afterDelete(_0x54323a){return _0x54323a['deleteResource']['paymentSystemPriceId']?deactivateStripeProductPricing(_0x54323a['deleteResource']['paymentSystemPriceId']):createError(paymentErrorMessages['noPaymentSystemIdAttachedToPricing']);}__name(afterDelete,'afterDelete');

export { afterDelete as afterDeletePricing, preUpdate as preUpdatePricing };
