import type { Request, Response } from "express";
import { Router } from "express";
import z from "zod";
import { preprintLabels } from "../../controller/labeling/preprint.js";

export const Preprint = z.object({
	scannerId: z.number(),
	lotNr: z.number(),
	machineId: z.number(), // 457=22, 458=23
	printerId: z.number(), // 457=22, 458=23
	layoutId: z.number(),
	numberOfCopies: z.number(),
	qtyToPrint: z.number().default(1),
});

const router = Router();

router.post("/preprint", async (req: Request, res: Response) => {
	const parsed = Preprint.safeParse(req.body);
	const print = await preprintLabels(req.body, req.user?.username || "");

	res
		.status(200)
		.json({ success: print.success, message: print.message, data: print.data });
});

export default router;
