"use strict";async function updateSpotWalletBalance(e,t,r,l,a,n,o=""){var d,i,c,s,u,p,w,y;try{null===(d=null==n?void 0:n.step)||void 0===d||d.call(n,`Processing ${a} for user ${e}, currency ${t}`);if(!o)throw new Error("idempotencyKey is required for updateSpotWalletBalance");switch(a){case"DEPOSIT":{const a=r-l;null===(i=null==n?void 0:n.step)||void 0===i||i.call(n,`Deposit: crediting ${a} (amount: ${r}, fee: ${l})`);const d=await wallet_1.walletService.credit({idempotencyKey:o,userId:e,walletType:"SPOT",currency:t,amount:a,operationType:"DEPOSIT",fee:l,description:`Deposit of ${r} ${t} (fee: ${l})`,metadata:{originalAmount:r,fee:l,type:"DEPOSIT"}});null===(c=null==n?void 0:n.success)||void 0===c||c.call(n,`Successfully deposited ${a} ${t}`);return{id:d.walletId,userId:e,currency:t,type:"SPOT",balance:d.newBalance,inOrder:d.newInOrder}}case"WITHDRAWAL":{const a=r+l;null===(s=null==n?void 0:n.step)||void 0===s||s.call(n,`Withdrawal: debiting ${a} (amount: ${r}, fee: ${l})`);const d=await wallet_1.walletService.debit({idempotencyKey:o,userId:e,walletType:"SPOT",currency:t,amount:a,operationType:"WITHDRAW",fee:l,description:`Withdrawal of ${r} ${t} (fee: ${l})`,metadata:{originalAmount:r,fee:l,type:"WITHDRAWAL"}});null===(u=null==n?void 0:n.success)||void 0===u||u.call(n,`Successfully withdrew ${r} ${t}`);return{id:d.walletId,userId:e,currency:t,type:"SPOT",balance:d.newBalance,inOrder:d.newInOrder}}case"REFUND_WITHDRAWAL":{const a=r+l;null===(p=null==n?void 0:n.step)||void 0===p||p.call(n,`Refund: crediting ${a} (amount: ${r}, fee: ${l})`);const d=await wallet_1.walletService.credit({idempotencyKey:o,userId:e,walletType:"SPOT",currency:t,amount:a,operationType:"REFUND_WITHDRAWAL",description:`Withdrawal refund of ${r} ${t} (fee refund: ${l})`,metadata:{originalAmount:r,fee:l,type:"REFUND_WITHDRAWAL"}});null===(w=null==n?void 0:n.success)||void 0===w||w.call(n,`Successfully refunded ${a} ${t}`);return{id:d.walletId,userId:e,currency:t,type:"SPOT",balance:d.newBalance,inOrder:d.newInOrder}}default:throw(0,error_1.createError)({statusCode:400,message:`Unknown operation type: ${a}`})}}catch(e){null===(y=null==n?void 0:n.fail)||void 0===y||y.call(n,e.message);if(e instanceof wallet_1.WalletError){const t=new Error(e.message);t.code=e.code;t.statusCode=e.statusCode;throw t}throw e}}async function creditSpotWallet(e,t,r,l,a,n){if(!a)throw new Error("idempotencyKey is required for creditSpotWallet");const o=await wallet_1.walletService.credit({idempotencyKey:a,userId:e,walletType:"SPOT",currency:t,amount:r,operationType:"DEPOSIT",description:l,metadata:n});return{id:o.walletId,balance:o.newBalance,inOrder:o.newInOrder}}async function debitSpotWallet(e,t,r,l,a,n){if(!a)throw new Error("idempotencyKey is required for debitSpotWallet");const o=await wallet_1.walletService.debit({idempotencyKey:a,userId:e,walletType:"SPOT",currency:t,amount:r,operationType:"WITHDRAW",description:l,metadata:n});return{id:o.walletId,balance:o.newBalance,inOrder:o.newInOrder}}async function holdSpotFunds(e,t,r,l,a,n){if(!a)throw new Error("idempotencyKey is required for holdSpotFunds");const o=await wallet_1.walletService.hold({idempotencyKey:a,userId:e,walletType:"SPOT",currency:t,amount:r,reason:l,metadata:n});return{id:o.walletId,balance:o.newBalance,inOrder:o.newInOrder}}async function releaseSpotFunds(e,t,r,l,a,n){if(!a)throw new Error("idempotencyKey is required for releaseSpotFunds");const o=await wallet_1.walletService.release({idempotencyKey:a,userId:e,walletType:"SPOT",currency:t,amount:r,reason:l,metadata:n});return{id:o.walletId,balance:o.newBalance,inOrder:o.newInOrder}}Object.defineProperty(exports,"__esModule",{value:!0});exports.updateSpotWalletBalance=updateSpotWalletBalance;exports.creditSpotWallet=creditSpotWallet;exports.debitSpotWallet=debitSpotWallet;exports.holdSpotFunds=holdSpotFunds;exports.releaseSpotFunds=releaseSpotFunds;const wallet_1=require("@b/services/wallet"),error_1=require("@b/utils/error");