import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
import { addReader } from "../controller/addReader.js";
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import type { User } from "../../../types/users.js";

import { apiHit } from "../../../globalUtils/apiHits.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { getReaders } from "../controller/getReaders.js";

const app = new OpenAPIHono();

export const ReaderBody = z.object({
    reader: z.string().openapi({ example: "wrapper1" }),
    readerIP: z.string().openapi({ example: "192.168.1.52" }),
});

app.openapi(
    createRoute({
        tags: ["rfid"],
        summary: "Get readers",
        method: "get",
        path: "/getreaders",
        responses: responses(),
    }),
    async (c: any) => {
        apiHit(c, { endpoint: "/getreaders" });

        const { data, error } = await tryCatch(getReaders());

        if (error) {
            return c.json({
                error,
            });
        }

        return c.json({
            data,
        });
    }
);

export default app;
