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";

/* POST /v1/unifi/sites/sync */
export default createRoute(
  "post",
  ["/sites/sync"],
  async (c) => {
    const sites = await unifiSites.syncSites();
    const response = apiResponse.successful(
      "UniFi Sites Synced Successfully!",
      sites,
    );
    return c.json(response, response.status as ContentfulStatusCode);
  },
  authMiddleware({ permissions: ["unifi.access", "unifi.sites.sync"] }),
);
