//http://usday1vms006:4000/api/v1/zebra/wrapper1
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { readTags } from "../controller/readTags.js";
import { apiHit } from "../../../globalUtils/apiHits.js";

const app = new OpenAPIHono();

const ParamsSchema = z.object({
    reader: z
        .string()
        .min(3)
        .openapi({
            param: {
                name: "reader",
                in: "path",
            },
            example: "1212121",
        }),
});

app.openapi(
    createRoute({
        tags: ["rfid"],
        summary: "Manual triggers the read function",
        method: "post",
        path: "/manualtrigger/{reader}",
        request: {
            params: ParamsSchema,
        },
        responses: responses(),
    }),
    async (c) => {
        const { reader } = c.req.valid("param");
        const manualTrigger = await readTags(reader);
        apiHit(c, { endpoint: `/manualtrigger/${reader}` });
        return c.json(
            {
                success: true,
                message: `A Manaul trigger was done on ${reader}`,
            },
            200
        );
    }
);

export default app;
