"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const db_1=require("@b/db"),redis_1=require("@b/utils/redis"),query_1=require("@b/utils/query"),error_1=require("@b/utils/error"),redis=redis_1.RedisSingleton.getInstance();exports.metadata={summary:"Get chart cache settings",operationId:"getChartSettings",tags:["Admin","Exchange","Chart"],responses:{200:{description:"Chart cache settings",content:{"application/json":{schema:{type:"object",properties:{cacheDays:{type:"number"},rateLimit:{type:"number"},intervals:{type:"array",items:{type:"string"}},autoUpdate:{type:"boolean"},exchangeBanStatus:{type:"object",properties:{isBanned:{type:"boolean"},unblockTime:{type:"number"}}}}}}}},401:query_1.unauthorizedResponse,500:query_1.serverErrorResponse},requiresAuth:!0,permission:"view.exchange.chart"};const DEFAULT_INTERVALS=["1m","5m","15m","30m","1h","2h","4h","6h","12h","1d","3d","1w"];exports.default=async()=>{try{const e=await db_1.models.settings.findOne({where:{key:"chart_cache"},raw:!0});let t={cacheDays:30,rateLimit:500,intervals:DEFAULT_INTERVALS,autoUpdate:!1};if(null==e?void 0:e.value)try{const r=JSON.parse(e.value);t={...t,...r}}catch(e){}let r={isBanned:!1,unblockTime:null,remainingSeconds:0};try{const e=await redis.get("exchange:ban_status");if(e){const t=parseInt(e,10),a=Date.now();t>a&&(r={isBanned:!0,unblockTime:t,remainingSeconds:Math.ceil((t-a)/1e3)})}}catch(e){}return{...t,exchangeBanStatus:r}}catch(e){throw(0,error_1.createError)({statusCode:500,message:`Failed to get chart settings: ${e.message}`})}};