import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";

const app = new OpenAPIHono();

// Define the request body schema
const requestSchema = z.object({
    ip: z.string().optional(),
    endpoint: z.string().optional(),
    action: z.string().optional(),
    stats: z.string().optional(),
});

// Define the response schema
const responseSchema = z.object({
    message: z.string(),
});

app.openapi(
    createRoute({
        tags: ["api"],
        summary: "Tracks the API posts and how often",
        method: "post",
        path: "/hits",
        request: {
            body: {
                content: {
                    "application/json": {schema: requestSchema},
                },
            },
        },
        responses: {
            200: {
                content: {
                    "application/json": {schema: responseSchema},
                },
                description: "Response message",
            },
        },
    }),
    async (c) => {
        const data = await c.req.json();

        //apiHit(data);

        // Return response with the received data
        return c.json({
            message: `Received name: ${data.name}, arrayData: ${data.arrayData}`,
        });
    }
);

export default app;
