import { createRoute } from "../../modules/api-utils/createRoute";
import { apiResponse } from "../../modules/api-utils/apiResponse";
import { ContentfulStatusCode } from "hono/utils/http-status";
import { authMiddleware } from "../middleware/authorization";
import {
  serializeCategoryTree,
  serializeEcosystemTree,
} from "../../modules/catalog-categories/catalogCategories";

/* /v1/procurement/categories */
export default createRoute(
  "get",
  ["/categories"],
  async (c) => {
    const categories = serializeCategoryTree();
    const ecosystems = serializeEcosystemTree();

    const response = apiResponse.successful(
      "Category and ecosystem data fetched successfully!",
      { categories, ecosystems },
    );

    return c.json(response, response.status as ContentfulStatusCode);
  },
  authMiddleware({ permissions: ["procurement.catalog.fetch.many"] }),
);
