"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:"Stores a new Investment Plan",operationId:"storeInvestmentPlan",tags:["Admin","Investment Plans"],logModule:"ADMIN_FIN",logTitle:"Create Investment Plan",requestBody:{required:!0,content:{"application/json":{schema:utils_1.investmentPlanUpdateSchema}}},responses:(0,query_1.storeRecordResponses)(utils_1.investmentPlanStoreSchema,"Investment Plan"),requiresAuth:!0,permission:"create.investment.plan"};exports.default=async e=>{const{body:t,ctx:n}=e,{name:a,title:s,description:r,image:i,minProfit:o,maxProfit:l,minAmount:u,maxAmount:d,invested:m,profitPercentage:c,status:p,defaultProfit:P,defaultResult:v,trending:f,durations:y,currency:g,walletType:I}=t;null==n||n.step("Preparing investment plan data");const q=y?[{model:"investmentPlanDuration",method:"addDurations",data:y.map(e=>"string"==typeof e?e:e.value),fields:{source:"planId",target:"durationId"}}]:[];y&&(null==n||n.step("Adding plan durations"));null==n||n.step("Creating investment plan");const x=await(0,query_1.storeRecord)({model:"investmentPlan",data:{name:a,title:s,description:r,image:i,minProfit:o,maxProfit:l,minAmount:u,maxAmount:d,invested:m,profitPercentage:c,status:p,defaultProfit:P,defaultResult:v,trending:f,currency:g,walletType:I},relations:q});null==n||n.success("Investment plan created successfully");return x};