import { createLog } from "../../logger/logger.js";
import { query } from "../../sqlServer/prodSqlServer.js";
import {
    totalInvNoRn,
    totalInvRn,
} from "../../sqlServer/querys/dataMart/totalINV.js";

export const getINV = async (rn: boolean) => {
    let inventory: any = [];

    let updatedQuery = totalInvNoRn;

    if (rn) {
        createLog(
            "info",
            "datamart",
            "datamart",
            "The user requested the running numbers this could take a while."
        );
        updatedQuery = totalInvRn;
    }

    try {
        inventory = await query(updatedQuery, "Gets Curruent inv");
        return { success: true, message: "Current inv", data: inventory.data };
    } catch (error) {
        console.log(error);
        return {
            success: false,
            message: "There was an error getting the inventory",
            data: error,
        };
    }
};
