"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const query_1=require("@b/utils/query"),utils_1=require("../utils");exports.metadata={summary:"Updates a specific Investment Plan",operationId:"updateInvestmentPlan",tags:["Admin","Investment Plans"],logModule:"ADMIN_FIN",logTitle:"Update Investment Plan",parameters:[{index:0,name:"id",in:"path",description:"ID of the Investment Plan to update",required:!0,schema:{type:"string"}}],requestBody:{description:"New data for the Investment Plan",content:{"application/json":{schema:utils_1.investmentPlanUpdateSchema}}},responses:(0,query_1.updateRecordResponses)("Investment Plan"),requiresAuth:!0,permission:"edit.investment.plan"};exports.default=async e=>{const{body:t,params:n,ctx:a}=e,{id:s}=n,{name:i,title:r,description:d,image:o,minProfit:u,maxProfit:l,minAmount:p,maxAmount:m,invested:c,profitPercentage:f,status:v,defaultProfit:P,defaultResult:g,trending:y,durations:I,currency:x,walletType:h}=t;null==a||a.step("Preparing investment plan update",{id:s,name:i,title:r});const q=I?[{model:"investmentPlanDuration",method:"addDurations",data:I.map(e=>"string"==typeof e?e:e.value),fields:{source:"planId",target:"durationId"}}]:[];I&&(null==a||a.step("Updating plan durations",{durationsCount:I.length}));null==a||a.step("Updating investment plan");const _=await(0,query_1.updateRecord)("investmentPlan",s,{name:i,title:r,description:d,image:o,minProfit:u,maxProfit:l,minAmount:p,maxAmount:m,invested:c,profitPercentage:f,status:v,defaultProfit:P,defaultResult:g,trending:y,currency:x,walletType:h},void 0,q);null==a||a.success("Investment plan updated successfully");return _};