// an external way to creating logs
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
import { prodUser } from "../controller/produser.js";

const app = new OpenAPIHono({ strict: false });

app.openapi(
    createRoute({
        tags: ["admin"],
        summary:
            "Runs a full crud on the user plus added icons if pc name provided and is online",
        method: "post",
        path: "/produser",
        responses: responses(),
    }),
    async (c) => {
        const { data: body, error: be } = await tryCatch(c.req.json());

        if (be) {
            return c.json({
                success: false,
                message: "Missing data.",
            });
        }
        const { data, error } = await tryCatch(prodUser(body));
        apiHit(c, { endpoint: "/newuser" });
        if (error) {
            console.log(error);
            return c.json({
                success: false,
                message: "Error processing create user.",
            });
        }

        return c.json({
            success: data.success,
            message: data.message,
            data: data.data,
        });
    }
);
export default app;
