'use strict';
import { getResourcesByName, updateResource } from '../../../meta/server/db/db.js';
import { resourceNames } from '../../../../fd-toolbox/resources/resource-names.js';
import { stripe, createStripeProduct, createStripeProductPricing } from './stripes.js';
import { pricingProps } from '../../../meta/core/resources/props/payment-plan-price-props.js';
import { logWarning } from '../../../../fd-toolbox/server/logging/logger.js';
import { stripeAuthenticationError } from './stripe-messages.js';
import _0x14f4e7 from 'stripe';

var __defProp=Object['defineProperty'],__name=(_0x3949dc,_0x335e3e)=>__defProp(_0x3949dc,'name',{'value':_0x335e3e,'configurable':!![]});async function syncPaymentPlansWithStripeAfterSeeding(){const _0x8d9482=await getResourcesByName(resourceNames['paymentPlan']),_0x5d264b=await stripe['products']['list']({'limit':0x64,'active':!![]});for(const _0x42e85a of _0x8d9482){let _0x2ed355=_0x5d264b['data']['find'](_0x316d1e=>_0x316d1e['metadata']&&_0x316d1e['metadata'][pricingProps['paymentPlanId']]===_0x42e85a['id']);_0x2ed355??=await createStripeProduct(_0x42e85a['name'],_0x42e85a['id']),_0x42e85a['paymentSystemId']!==_0x2ed355['id']&&await updateResource({'id':_0x42e85a['id'],'paymentSystemId':_0x2ed355['id']},resourceNames['paymentPlan']);}}__name(syncPaymentPlansWithStripeAfterSeeding,'syncPaymentPlansWithStripeAfterSeeding');async function syncPricingsWithStripeAfterSeeding(){const _0xe8ea82=await getResourcesByName(resourceNames['pricing']),_0x578192=await stripe['products']['list']({'limit':0x64,'active':!![]}),_0x432198=await stripe['prices']['list']({'limit':0x64,'active':!![]});for(const _0x118ae1 of _0xe8ea82){const _0x43dc3b=_0x432198['data']['find'](_0x15de60=>_0x15de60['metadata']&&_0x15de60['metadata'][pricingProps['id']]===_0x118ae1['id']);if(_0x43dc3b)_0x118ae1['paymentSystemPriceId']!==_0x43dc3b['id']&&await updateResource({'id':_0x118ae1['id'],'paymentSystemPriceId':_0x43dc3b['id']},resourceNames['pricing']);else {let _0x579ba0=_0x578192['data']['find'](_0x1e3252=>_0x1e3252['metadata']&&_0x1e3252['metadata'][pricingProps['paymentPlanId']]===_0x118ae1['paymentPlanId']);const _0x4176d1=await createStripeProductPricing(_0x579ba0['id'],_0x118ae1['currency'],_0x118ae1['price'],_0x118ae1['id'],_0x118ae1['billingInterval'],![]);await updateResource({'id':_0x118ae1['id'],'paymentSystemPriceId':_0x4176d1['id']},resourceNames['pricing']);}}}__name(syncPricingsWithStripeAfterSeeding,'syncPricingsWithStripeAfterSeeding');async function syncPaymentPlansAndPricesAfterSeeding(){try{await syncPaymentPlansWithStripeAfterSeeding(),await syncPricingsWithStripeAfterSeeding();}catch(_0x1fe3cf){if(_0x1fe3cf instanceof _0x14f4e7['errors']['StripeAuthenticationError']){logWarning(stripeAuthenticationError);return;}throw _0x1fe3cf;}}__name(syncPaymentPlansAndPricesAfterSeeding,'syncPaymentPlansAndPricesAfterSeeding');

export { syncPaymentPlansAndPricesAfterSeeding, syncPaymentPlansWithStripeAfterSeeding, syncPricingsWithStripeAfterSeeding };
