"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const utils_1=require("@b/api/admin/system/utils"),utils_2=require("../../utils"),query_1=require("@b/utils/query"),error_1=require("@b/utils/error");exports.metadata={summary:"Activate Exchange License",operationId:"activateLicense",tags:["Admin","Settings","Exchange"],description:"Activates the license for the exchange product.",requiresAuth:!0,parameters:[{index:0,in:"path",name:"productId",description:"Product ID whose license to activate",required:!0,schema:{type:"string"}}],requestBody:{description:"Product ID, purchase code, and envato username for license activation.",content:{"application/json":{schema:{type:"object",properties:{purchaseCode:{type:"string",description:"Purchase code for the license."},envatoUsername:{type:"string",description:"Envato username."}},required:["purchaseCode","envatoUsername"]}}},required:!0},responses:{200:{description:"License activated successfully"},401:query_1.unauthorizedResponse,404:(0,query_1.notFoundMetadataResponse)("License"),500:query_1.serverErrorResponse},permission:"edit.exchange",logModule:"ADMIN_FIN",logTitle:"Activate Exchange Provider"};exports.default=async e=>{const{body:t,params:s,ctx:r}=e,{purchaseCode:i,envatoUsername:a}=t,{productId:n}=s;if(!n||!i||!a)throw(0,error_1.createError)({statusCode:400,message:"All fields are required for license activation."});null==r||r.step("Activating license");const o=await(0,utils_1.activateLicense)(n,i,a);if(o.status){null==r||r.step("Saving license");await(0,utils_2.saveLicense)(n,a)}null==r||r.success();return o};