import { addDays, subDays } from "date-fns";
import { format } from "date-fns-tz";
import { Router } from "express";
import { runProdApi } from "../utils/prodEndpoint.utils.js";
import { apiReturn } from "../utils/returnHelper.utils.js";

const r = Router();

r.get("/", async (_, res) => {
	const orders = await runProdApi({
		method: "post",
		endpoint: "/public/v1.0/OutboundDeliveries/LoadingOrders/Search",
		data: [
			{
				loadingDateFrom: format(subDays(new Date(Date.now()), 3), "yyyy-MM-dd"),
				loadingDateTo: format(addDays(new Date(Date.now()), 3), "yyyy-MM-dd"),
				states: [
					1, // planned
					2, // loading
				],
				//isCommissioned: true,
			},
		],
	});
	return apiReturn(res, {
		success: true,
		level: "info",
		module: "dockdoor",
		subModule: "current Active loading orders",
		message: `Current active loading loaders.`,
		data: orders?.data ?? [],
		status: 200,
	});
});

export default r;
