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";
import { z } from "zod";

/* POST /v1/unifi/sites/create */
export default createRoute(
  "post",
  ["/sites/create"],
  async (c) => {
    const body = await c.req.json();
    const schema = z.object({ description: z.string().min(1) }).strict();
    const { description } = schema.parse(body);

    const site = await unifiSites.createSite(description);
    const response = apiResponse.successful(
      "UniFi Site Created Successfully!",
      site,
    );
    return c.json(response, response.status as ContentfulStatusCode);
  },
  authMiddleware({ permissions: ["unifi.access", "unifi.sites.create"] }),
);
