import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { createLog } from "../../logger/logger.js";
import { query } from "../../sqlServer/prodSqlServer.js";
import { forecastByAvs } from "../../sqlServer/querys/dataMart/forecast.js";

// type ArticleData = {
//     id: string
// }
export const getForecastByAv = async (avs: string) => {
    let articles: any = [];

    if (!avs) {
        return {
            success: false,
            message: `Missing av's please send at least one over`,
            data: [],
        };
    }

    const { data, error } = (await tryCatch(
        query(forecastByAvs.replace("[articles]", avs), "ForecastData by av")
    )) as any;

    if (error) {
        createLog(
            "error",
            "datamart",
            "datamart",
            `There was an error getting the forecast info: ${JSON.stringify(
                error
            )}`
        );
        return {
            success: false,
            messsage: `There was an error getting the forecast info`,
            data: error,
        };
    }

    articles = data.data;

    return {
        success: true,
        message: "Forecast Data",
        data: articles,
    };
};
