"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const query_1=require("@b/utils/query"),error_1=require("@b/utils/error"),db_1=require("@b/db");exports.metadata={summary:"Deletes a specific user by UUID",operationId:"deleteUserByUuid",tags:["Admin","CRM","User"],logModule:"ADMIN_CRM",logTitle:"Delete user",parameters:(0,query_1.deleteRecordParams)("user"),responses:(0,query_1.deleteRecordResponses)("User"),requiresAuth:!0,permission:"delete.user"};exports.default=async e=>{const{params:r,query:s,user:t,ctx:o}=e;null==o||o.step("Validating user authorization");if(!(null==t?void 0:t.id))throw(0,error_1.createError)({statusCode:401,message:"Unauthorized"});const d=await db_1.models.user.findByPk(t.id,{include:[{model:db_1.models.role,as:"role"}]});if(!d||!d.role||"Super Admin"!==d.role.name)throw(0,error_1.createError)({statusCode:403,message:"Forbidden - Only Super Admins can delete users"});const{id:u}=r;null==o||o.step("Validating target user");const a=await db_1.models.user.findOne({where:{id:u},include:[{model:db_1.models.role,as:"role"}]});if(a&&a.role&&"Super Admin"===a.role.name)throw(0,error_1.createError)({statusCode:403,message:"Forbidden - You cannot delete another Super Admin account"});null==o||o.step("Deleting user");const l=await(0,query_1.handleSingleDelete)({model:"user",id:u,query:s});null==o||o.success();return l};