import { createTRPCRouter, protectedProcedure } from "$lib/trpc/t";
import { db } from "@pkg/db";
import { OrderRepository } from "../data/repository";
import { OrderController } from "./controller";
import { paginationModel } from "@pkg/logic/core/pagination.utils";
import { z } from "zod";

export const orderRouter = createTRPCRouter({
	listOrders: protectedProcedure.query(async ({ ctx }) => {
		const oc = new OrderController(new OrderRepository(db));
		return await oc.listAllOrders();
	}),

	getOrdersPaginatedInfo: protectedProcedure
		.input(z.object({ info: paginationModel, fetchNext: z.boolean() }))
		.query(async ({ ctx, input }) => {
			const oc = new OrderController(new OrderRepository(db));
			return await oc.getOrdersPaginatedInfo(
				ctx.user,
				input.info,
				input.fetchNext,
			);
		}),
});
