"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const notification_1=require("@b/services/notification"),errors_1=require("@b/utils/schema/errors");exports.metadata={summary:"Clean Queue Jobs",description:"Remove old completed and failed jobs from the notification queue",operationId:"cleanQueueJobs",tags:["Admin","Notification","Queue"],requiresAuth:!0,permission:"access.notification.settings",requestBody:{required:!1,content:{"application/json":{schema:{type:"object",properties:{olderThan:{type:"number",description:"Remove jobs older than this many milliseconds (default: 24 hours)",default:864e5}}}}}},responses:{200:{description:"Queue cleaned successfully",content:{"application/json":{schema:{type:"object",properties:{success:{type:"boolean"},removed:{type:"object"}}}}}},401:errors_1.unauthorizedResponse,500:errors_1.serverErrorResponse}};exports.default=async e=>{var o,s,t;const{body:i,ctx:n}=e;try{null===(o=null==n?void 0:n.step)||void 0===o||o.call(n,"Cleaning old queue jobs");const e=(null==i?void 0:i.olderThan)||864e5,t=await notification_1.notificationQueue.cleanOldJobs(e);null===(s=null==n?void 0:n.success)||void 0===s||s.call(n,`Cleaned ${t.length} jobs from queue`);return{success:!0,message:"Queue cleaned successfully",removed:{total:t.length,jobIds:t.slice(0,10)},olderThan:`${(e/36e5).toFixed(1)} hours`}}catch(e){null===(t=null==n?void 0:n.fail)||void 0===t||t.call(n,e.message);throw e}};