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

import { responses } from "../../../../globalUtils/routeDefs/responses.js";

import { getAllUsers } from "../../controllers/userAdmin/getUsers.js";
import { authMiddleware } from "../../middleware/authMiddleware.js";
import hasCorrectRole from "../../middleware/roleCheck.js";

const app = new OpenAPIHono();

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

export default app;
