import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { authMiddleware } from "../../../auth/middleware/authMiddleware.js";
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { getStockSiloData } from "../../controller/siloAdjustments/getCurrentStockSiloData.js";
import { apiHit } from "../../../../globalUtils/apiHits.js";

const app = new OpenAPIHono();

app.openapi(
    createRoute({
        tags: ["logistics"],
        summary: "Returns current stock levels for silos",
        method: "get",
        path: "/getstocksilo",
        middleware: authMiddleware,
        // request: {
        //     params: ParamsSchema,
        //     body: { content: { "application/json": { schema: Body } } },
        // },
        // description:
        //     "Creates a silo adjustment for the silo if and stores the stock numbers.",
        responses: responses(),
    }),
    async (c: any) => {
        apiHit(c, { endpoint: "/getstocksilo" });

        try {
            //return apiReturn(c, true, access?.message, access?.data, 200);

            const silo = await getStockSiloData();
            return c.json(
                {
                    success: silo?.success ?? false,
                    message: silo?.message ?? "Failed to get silo data",
                    data: silo?.data ?? [],
                },
                200
            );
        } catch (error) {
            return c.json(
                {
                    success: false,
                    message: "Missing data please try again",
                    error,
                },
                400
            );
        }
    }
);
export default app;
