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/wifi/:wlanId/ppsk */
export default createRoute(
  "get",
  ["/site/:id/wifi/:wlanId/ppsk"],
  async (c) => {
    const site = await unifiSites.fetch(c.req.param("id"));
    const wlanId = c.req.param("wlanId");
    const ppsks = await unifiSites.getPrivatePSKs(site.siteId, wlanId);
    const response = apiResponse.successful(
      "UniFi Private PSKs Fetched Successfully!",
      ppsks,
    );
    return c.json(response, response.status as ContentfulStatusCode);
  },
  authMiddleware({
    permissions: ["unifi.access", "unifi.site.wifi", "unifi.site.wifi.ppsk"],
  }),
);
