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

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

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

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

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

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

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