"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const exchange_1=__importDefault(require("@b/utils/exchange")),db_1=require("@b/db"),query_1=require("@b/utils/query"),error_1=require("@b/utils/error");exports.metadata={summary:"Verify Exchange Credentials",operationId:"verifyExchangeCredentials",tags:["Admin","Exchange","Credentials"],description:"Verifies the API credentials for the exchange provider.",requiresAuth:!0,parameters:[{index:0,in:"path",name:"productId",description:"Product ID of the exchange to verify credentials for",required:!0,schema:{type:"string"}}],responses:{200:{description:"Credentials verification result",content:{"application/json":{schema:{type:"object",properties:{status:{type:"boolean",description:"Whether the credentials are valid"},message:{type:"string",description:"Verification result message"}}}}}},401:query_1.unauthorizedResponse,404:(0,query_1.notFoundMetadataResponse)("Exchange"),500:query_1.serverErrorResponse},permission:"edit.exchange",logModule:"ADMIN_FIN",logTitle:"Verify Exchange Provider"};exports.default=async e=>{const{params:r,ctx:t}=e,{productId:s}=r;if(!s)throw(0,error_1.createError)({statusCode:400,message:"Product ID is required for credentials verification."});null==t||t.step("Finding exchange");const i=await db_1.models.exchange.findOne({where:{productId:s}});if(!i)throw(0,error_1.createError)({statusCode:404,message:"Exchange not found"});null==t||t.step("Testing exchange credentials");const a=await exchange_1.default.testExchangeCredentials(i.name,t);null==t||t.success();return a};