"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const error_1=require("@b/utils/error"),db_1=require("@b/db"),Websocket_1=require("@b/handler/Websocket"),query_1=require("@b/utils/query");exports.metadata={summary:"Closes a support ticket",description:"Closes a support ticket identified by its UUID.",operationId:"closeTicket",tags:["Support"],requiresAuth:!0,logModule:"USER",logTitle:"Close support ticket",parameters:[{index:0,name:"id",in:"path",required:!0,description:"The UUID of the ticket to close",schema:{type:"string"}}],responses:(0,query_1.updateRecordResponses)("Support Ticket")};exports.default=async e=>{const{params:t,ctx:s}=e,{id:r}=t;null==s||s.step("Closing support ticket");await db_1.models.supportTicket.update({status:"CLOSED"},{where:{id:r}});null==s||s.step("Retrieving updated ticket");const o=await db_1.models.supportTicket.findOne({where:{id:r}});if(!o){null==s||s.fail("Ticket not found");throw(0,error_1.createError)({statusCode:404,message:"Ticket not found"})}const i={id:o.id};null==s||s.step("Broadcasting ticket closure via WebSocket");Websocket_1.messageBroker.broadcastToSubscribedClients(`/api/user/support/ticket/${r}`,i,{method:"update",data:{status:"CLOSED",updatedAt:new Date}});null==s||s.success("Ticket closed successfully");return{message:"Ticket closed successfully"}};