import { runProdApi } from "../../../../globalUtils/runProdApi.js";
import { tryCatch } from "../../../../globalUtils/tryCatch.js";

export const attachSilo = async (data: any) => {
    /**
     * Detachs a silo
     */

    const detachData = {
        endpoint: "/public/v1.0/IssueMaterial/AssignSiloToMachine",
        data: [
            {
                laneId: data.laneId,
                machineId: data.machineId,
                productionLotId: data.productionLotId,
            },
        ],
    };

    const { data: d, error } = await tryCatch(runProdApi(detachData));

    if (error) {
        return {
            success: false,
            message: "Error processing attachingSilo data",
            data: error,
        };
    }

    if (!d.success) {
        return {
            success: false,
            message: "Error processing silo attach data",
            data: d.message,
        };
    }

    return {
        success: true,
        message: "silo attach was completed",
        data: d.data,
    };
};
