"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const query_1=require("@b/utils/query"),utils_1=require("./utils"),error_1=require("@b/utils/error");exports.metadata={summary:"Stores a new deposit method",operationId:"storeDepositMethod",tags:["Admin","Deposit Methods"],requestBody:{required:!0,content:{"application/json":{schema:utils_1.depositMethodUpdateSchema}}},responses:(0,query_1.storeRecordResponses)(utils_1.DepositMethodSchema,"Deposit Method"),requiresAuth:!0,permission:"create.deposit.method",logModule:"ADMIN_FIN",logTitle:"Create deposit method"};exports.default=async e=>{const{body:t,ctx:s}=e,{title:o,instructions:r,image:i,fixedFee:a,percentageFee:d,minAmount:u,maxAmount:n,customFields:c}=t;null==s||s.step("Validating deposit method data");let l=Array.isArray(c)?c:[];if("string"==typeof c)try{const e=JSON.parse(c);l=Array.isArray(e)?e:[]}catch(e){throw(0,error_1.createError)({statusCode:400,message:"Invalid JSON format for customFields"})}null==s||s.step("Creating deposit method record");const m=await(0,query_1.storeRecord)({model:"depositMethod",data:{title:o,instructions:r,image:i,fixedFee:a,percentageFee:d,minAmount:u,maxAmount:n,customFields:l}});null==s||s.success("Deposit method created successfully");return m};