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

/* GET /v1/unifi/site/:id/speed-profiles */
export default createRoute(
  "get",
  ["/site/:id/speed-profiles"],
  async (c) => {
    const site = await unifiSites.fetch(c.req.param("id"));
    const profiles = await unifiSites.getUserGroups(site.siteId);
    const response = apiResponse.successful(
      "UniFi Speed Profiles Fetched Successfully!",
      profiles,
    );
    return c.json(response, response.status as ContentfulStatusCode);
  },
  authMiddleware({
    permissions: ["unifi.access", "unifi.site.speed-profiles"],
  }),
);
