"use strict";async function handler(e){const{user:t,body:r,ctx:i}=e;if(!t){null==i||i.fail("User not authenticated");throw(0,error_1.createError)(401,"Unauthorized access")}const{model:s,modelConfig:a,timeframe:o,charts:n,kpis:p}=r;if(!s){null==i||i.fail("Model parameter missing");throw(0,error_1.createError)(400,"Missing model parameter")}const c={userId:t.id,...a||{}};if(!db_1.models[s]){null==i||i.fail("Invalid model specified");throw(0,error_1.createError)(400,"Invalid or missing model")}null==i||i.step(`Retrieving analytics data for model: ${s}`);const l=await(0,chart_1.getChartData)({model:db_1.models[s],timeframe:o,charts:n,kpis:p,where:c});null==i||i.success("Analytics data retrieved successfully");return l}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:["User","CRM","User","Analytics"],logModule:"USER",logTitle:"Get analytics data",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"}}}},modelConfig:{type:"object"}},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};