"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const db_1=require("@b/db"),error_1=require("@b/utils/error");exports.metadata={summary:"Update a KYC Level",description:"Updates an existing KYC level with the provided details.",operationId:"updateKycLevel",tags:["KYC","Levels"],parameters:[{index:0,name:"id",in:"path",description:"KYC level ID",required:!0,schema:{type:"string"}}],requestBody:{description:"KYC level update data",required:!0,content:{"application/json":{schema:{type:"object",properties:{name:{type:"string"},description:{type:"string"},level:{type:"number"},fields:{type:"array",items:{type:"object"}},features:{type:"array",items:{type:"string"}},serviceId:{type:"string",description:"Verification service ID"},status:{type:"string",enum:["ACTIVE","DRAFT","INACTIVE"],description:"Level status"}},required:["name","description","level","status"]}}}},responses:{200:{description:"KYC level updated successfully.",content:{"application/json":{schema:{type:"object",properties:{message:{type:"string"},level:{type:"object"}}}}}},400:{description:"Missing required fields."},404:{description:"KYC level not found."},500:{description:"Internal Server Error."}},permission:"edit.kyc.level",requiresAuth:!0,logModule:"ADMIN_CRM",logTitle:"Update KYC level"};exports.default=async e=>{const{params:t,body:s,ctx:r}=e,{id:i}=t;if(!i)throw(0,error_1.createError)({statusCode:400,message:"Missing level ID"});null==r||r.step(`Fetching KYC level ${i}`);const a=await db_1.models.kycLevel.findByPk(i);if(!a)throw(0,error_1.createError)({statusCode:404,message:"KYC level not found"});const{name:l,description:d,level:n,fields:o,features:p,serviceId:c,status:u}=s;let v=null;if(c&&""!==c.trim()){null==r||r.step("Validating verification service");if(!await db_1.models.kycVerificationService.findByPk(c))throw(0,error_1.createError)({statusCode:400,message:`Invalid serviceId: ${c}. Service does not exist.`});v=c}null==r||r.step("Updating KYC level");await a.update({name:l,description:d,level:n,fields:o,features:p,serviceId:v,status:u,updatedAt:new Date});null==r||r.success("KYC level updated successfully");return{message:"KYC level updated successfully."}};