"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const query_1=require("@b/utils/query"),db_1=require("@b/db"),error_1=require("@b/utils/error"),utils_1=require("../utils");exports.metadata={summary:"Retrieves a single investment by UUID",description:"Fetches detailed information about a specific investment identified by its UUID, including associated plan and user details.",operationId:"getInvestment",tags:["Finance","Investment"],requiresAuth:!0,parameters:[{index:0,name:"id",in:"path",required:!0,description:"The Id of the investment to retrieve",schema:{type:"string"}},{name:"type",in:"query",description:"The type of investment to retrieve",schema:{type:"string"}}],responses:{200:{description:"Investment retrieved successfully",content:{"application/json":{schema:{type:"object",properties:{...utils_1.baseInvestmentSchema,user:{type:"object",properties:utils_1.baseUserSchema},plan:{type:"object",properties:utils_1.baseInvestmentPlanSchema}}}}}},401:query_1.unauthorizedResponse,404:(0,query_1.notFoundMetadataResponse)("Investment"),500:query_1.serverErrorResponse}};exports.default=async e=>{const{user:t,params:s,query:r,ctx:n}=e;if(!t)throw(0,error_1.createError)({statusCode:401,message:"Unauthorized"});const{id:i}=s,{type:a}=r;if(!a||"string"!=typeof a)throw(0,error_1.createError)({statusCode:400,message:"Invalid investment type"});null==n||n.step(`Fetching ${a} investment ${i}`);let o,d,u;switch(a.toLowerCase()){case"general":o=db_1.models.investment;d=db_1.models.investmentPlan;u=db_1.models.investmentDuration;break;case"forex":o=db_1.models.forexInvestment;d=db_1.models.forexPlan;u=db_1.models.forexDuration}const m=await o.findOne({where:{id:i,userId:t.id},include:[{model:d,as:"plan"},{model:u,as:"duration"},{model:db_1.models.user,as:"user",attributes:["id","firstName","lastName","email","avatar"]}]});if(!m)throw(0,error_1.createError)({statusCode:404,message:"Investment not found"});null==n||n.success("Investment retrieved successfully");return m.get({plain:!0})};