import { emitToRoom } from "../socket.io/roomEmitter.socket.js";
import { hasRoomMembers } from "../socket.io/socket.manager.js";
import { runProdApi } from "../utils/prodEndpoint.utils.js";

export const ppoRun = async () => {
	const laneData = await runProdApi({
		method: "post",
		endpoint: "/public/v1.1/Warehousing/GetWarehouseUnits",
		data: [
			{
				laneIds: ["0"],
			},
		],
	});

	return laneData?.data ?? [];
};

export const ppooMonitoring = async () => {
	const roomId = "inventory:ppoo";

	if (!hasRoomMembers(roomId)) {
		return;
	}

	emitToRoom(roomId, {
		type: "snapshot",
		items: await ppoRun(),
		createdAt: new Date().toISOString(),
	} as any);
};
