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

import { responses } from "../../../../globalUtils/routeDefs/responses.js";
import { authMiddleware } from "../../middleware/authMiddleware.js";
import hasCorrectRole from "../../middleware/roleCheck.js";
import { getAllUsersRoles } from "../../controllers/userAdmin/getAllUserRoles.js";

const app = new OpenAPIHono();

app.openapi(
    createRoute({
        tags: ["Auth:admin"],
        summary: "Gets Users Roles",
        method: "get",
        path: "/allusersroles",
        middleware: [
            authMiddleware,
            hasCorrectRole(["admin", "systemAdmin"], "admin"),
        ],
        responses: responses(),
    }),
    async (c) => {
        // apit hit
        //apiHit(c, {endpoint: "api/auth/register"});
        const allUsers: any = await getAllUsersRoles();
        return c.json({
            success: allUsers?.success,
            message: allUsers?.message,
            data: allUsers?.data,
        });
    }
);

export default app;
