import { createLogger } from "../logger/logger.js";
import { prodQuery } from "../prodSql/prodQuery.js";
import { machineCheck } from "../prodSql/querys/general/machineInfo.js";

export const getMachineData = async (machine: string) => {
	const log = createLogger({
		module: "logistics",
		subModule: "preprint",
	});
	let updateQuery = machineCheck.replaceAll("[loc]", machine!);

	if (machine === "all") {
		updateQuery = machineCheck.replaceAll("and [Location] = [loc]", "");
	}

	// create blank lots in case there is an error and dose not work
	let mac = [];

	try {
		const getMac: any = await prodQuery(updateQuery, "Machine id check");

		mac = getMac.data;
		// console.log("Machine data", mac); // removed due to swr being activated
	} catch (err) {
		log.error({ error: err }, `Error with Machine id Check query: ${err}`);
	}

	return mac;
};
