"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const error_1=require("@b/utils/error"),db_1=require("@b/db");exports.metadata={summary:"Deletes an API key",description:"Deletes an API key by its ID.",operationId:"deleteApiKey",tags:["API Key Management"],logModule:"USER",logTitle:"Delete API key",parameters:[{index:0,name:"id",in:"path",required:!0,description:"The ID of the API key to delete",schema:{type:"string"}}],responses:{200:{description:"API key deleted successfully",content:{"application/json":{schema:{type:"object",properties:{message:{type:"string"}}}}}},401:{description:"Unauthorized"},404:{description:"API key not found"},500:{description:"Server error"}},requiresAuth:!0};exports.default=async e=>{const{user:t,params:r,ctx:s}=e;if(!t){null==s||s.fail("User not authenticated");throw(0,error_1.createError)({statusCode:401,message:"Unauthorized"})}const{id:o}=r;null==s||s.step("Finding API key");const i=await db_1.models.apiKey.findOne({where:{id:o,userId:t.id}});if(!i){null==s||s.fail("API Key not found");throw(0,error_1.createError)({statusCode:404,message:"API Key not found"})}null==s||s.step("Deleting API key");await i.destroy({force:!0});null==s||s.success("API Key deleted successfully");return{message:"API Key deleted successfully"}};