import { abbottOrders } from "./mappings/abbottTruckList.js";
import { energizerOrders } from "./mappings/energizerOrdersIn.js";
import { macroImportOrders } from "./mappings/macroImport.js";
import { standardOrders } from "./mappings/standardOrders.js";

export const ordersIn = async (data: any, user: any) => {
    /**
     * Bulk orders in, and custom file parsing.
     */

    let success = true;
    let message = "";
    let orderData: any = [];

    // what type of order are we dealing with?
    if (data["fileType"] === "standard") {
        // run the standard orders in
        const standard = await standardOrders(data["postOrders"], user);
        success = standard.success ?? false;
        message = standard.message ?? "Error posting Standard Orders";
        orderData = standard.data;
    }

    if (data["fileType"] === "abbott") {
        // orders in
        const abbott = await abbottOrders(data["postOrders"], user);
        success = abbott.success ?? false;
        message = abbott.message ?? "Error posting Abbott Orders";
        orderData = abbott.data;
    }

    if (data["fileType"] === "energizer") {
        // orders in
        const energizer = await energizerOrders(data["postOrders"], user);
        success = energizer.success ?? false;
        message = energizer.message ?? "Error posting Energizer Orders";
        orderData = energizer.data;
    }

    if (data["fileType"] === "loreal") {
        // orders in
    }

    if (data["fileType"] === "pg") {
        // orders in
    }

    if (data["fileType"] === "macro") {
        // orders in
        const macro = await macroImportOrders(data["postOrders"], user);
        success = macro.success ?? false;
        message = macro.message ?? "Error posting Macro Orders";
        orderData = macro.data;
    }

    return {
        success,
        message,
        data: orderData,
    };
};
