"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const console_1=require("@b/utils/console"),redis_1=require("@b/utils/redis"),redis=redis_1.RedisSingleton.getInstance();exports.metadata={requiresAuth:!0,permission:"manage.exchange.chart",summary:"WebSocket endpoint for chart build job progress",description:"Subscribe to real-time progress updates for chart build jobs"};exports.default=async(e,r)=>{try{let e;if("string"==typeof r)try{e=JSON.parse(r)}catch(e){return{type:"error",message:"Invalid JSON message"}}else e=r;if(!e||!e.action)return{type:"error",message:"Invalid message structure"};const{action:s,payload:t}=e;switch(s){case"SUBSCRIBE":if(null==t?void 0:t.jobId){const e=await redis.get(`chart_build_job:${t.jobId}`);return{type:"subscription",status:"success",message:`Subscribed to job ${t.jobId}`,data:e?JSON.parse(e):{status:"pending",progress:0}}}return{type:"error",message:"Job ID required"};case"UNSUBSCRIBE":return(null==t?void 0:t.jobId)?{type:"subscription",status:"success",message:`Unsubscribed from job ${t.jobId}`}:{type:"error",message:"Job ID required"};case"GET_STATUS":if(null==t?void 0:t.jobId){const e=await redis.get(`chart_build_job:${t.jobId}`);return e?{type:"status",data:JSON.parse(e)}:{type:"status",data:{status:"not_found"}}}return{type:"error",message:"Job ID required"};default:return{type:"error",message:`Unknown action: ${s}`}}}catch(e){console_1.logger.error("Chart Build WS",`Error: ${e.message}`);return{type:"error",message:e.message}}};