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/site/:id/unlink */
export default createRoute(
  "post",
  ["/site/:id/unlink"],
  async (c) => {
    const siteId = c.req.param("id");
    const site = await unifiSites.unlinkFromCompany(siteId);
    const response = apiResponse.successful(
      "UniFi Site Unlinked from Company Successfully!",
      site,
    );
    return c.json(response, response.status as ContentfulStatusCode);
  },
  authMiddleware({ permissions: ["unifi.access", "unifi.sites.link"] }),
);
