"use strict";async function getScyllaChartData(e){try{return(await Promise.resolve().then(()=>__importStar(require("@b/api/(ext)/ecosystem/utils/scylla/chart")))).getChartData(e)}catch(e){throw(0,error_1.createError)(400,"Scylla extension is not installed or available")}}async function handler(e){const{body:t,ctx:r}=e,{model:a,modelConfig:i,db:s="mysql",keyspace:n,timeframe:o,charts:c,kpis:l}=t;null==r||r.step("Validating analysis request");if(!a)throw(0,error_1.createError)(400,"Missing model parameter");const p=i||{};if("mysql"===s){null==r||r.step("Processing MySQL analytics");if(!db_1.models[a]){console.error(`Model '${a}' not found. Available models:`,Object.keys(db_1.models));throw(0,error_1.createError)(400,`Invalid or missing model: ${a}`)}const e=await(0,chart_1.getChartData)({model:db_1.models[a],timeframe:o,charts:c,kpis:l,where:p});null==r||r.success();return e}null==r||r.step("Processing Scylla analytics");if(!n)throw(0,error_1.createError)(400,"Missing keyspace parameter");const y="ecosystem"===n?process.env.SCYLLA_KEYSPACE||"trading":process.env.SCYLLA_FUTURES_KEYSPACE||"futures",u=await getScyllaChartData({model:a,keyspace:y,timeframe:o,charts:c,kpis:l,where:p});null==r||r.success();return u}var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,a){void 0===a&&(a=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}});Object.defineProperty(e,a,i)}:function(e,t,r,a){void 0===a&&(a=r);e[a]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(){var e=function(t){e=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t};return e(t)};return function(t){if(t&&t.__esModule)return t;var r={};if(null!=t)for(var a=e(t),i=0;i<a.length;i++)"default"!==a[i]&&__createBinding(r,t,a[i]);__setModuleDefault(r,t);return r}}();Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;exports.default=handler;const db_1=require("@b/db"),error_1=require("@b/utils/error"),chart_1=require("@b/utils/chart");exports.metadata={summary:"Gets chart data for user analytics (all in POST body)",operationId:"getAnalyticsData",tags:["Admin","CRM","User","Analytics"],logModule:"ADMIN_SYS",logTitle:"Run analysis",requestBody:{required:!0,content:{"application/json":{schema:{type:"object",properties:{model:{type:"string"},timeframe:{type:"string"},db:{type:"string"},keyspace:{type:"string",nullable:!0},charts:{type:"array",items:{type:"object",properties:{id:{type:"string"},title:{type:"string"},type:{type:"string",enum:["line","bar","pie","stackedBar","stackedArea"]},model:{type:"string"},metrics:{type:"array",items:{type:"string"}}}}},kpis:{type:"array",items:{type:"object",properties:{id:{type:"string"},title:{type:"string"},metric:{type:"string"},model:{type:"string"},icon:{type:"string"}}}}},required:["model","timeframe","charts","kpis"]}}}},responses:{200:{description:"Analytics data object matching your shape (kpis + chart keys)",content:{"application/json":{schema:{type:"object",properties:{kpis:{type:"array",items:{type:"object",properties:{id:{type:"string"},title:{type:"string"},value:{type:"number"},change:{type:"number"},trend:{type:"array",items:{type:"object",properties:{date:{type:"string"},value:{type:"number"}}}},icon:{type:"string"}}}}},additionalProperties:!0}}}},401:{description:"Unauthorized access"}},requiresAuth:!0,permission:"access.admin"};