import { Hono } from "hono/tiny";
import { createRoute } from "../../modules/api-utils/createRoute";
import { roles } from "../../managers/roles";
import { apiResponse } from "../../modules/api-utils/apiResponse";
import { ContentfulStatusCode } from "hono/utils/http-status";
import { authMiddleware } from "../middleware/authorization";

/* DELETE /v1/role/:identifier */
export default createRoute(
  "delete",
  ["/:identifier"],

  async (c) => {
    const identifier = c.req.param("identifier");

    const role = await roles.fetch(identifier);
    await role.delete();

    const response = apiResponse.successful(
      "Role Deleted Successfully!",
      role.toJson(),
    );
    return c.json(response, response.status as ContentfulStatusCode);
  },
  authMiddleware({ permissions: ["role.delete"] }),
);
