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

/* /v1/company/companies/[id]/sites */
export default createRoute(
  "get",
  ["/companies/:identifier/sites"],

  async (c) => {
    const company = await companies.fetch(c.req.param("identifier"));
    const sites = await company.fetchSites();

    const response = apiResponse.successful(
      "Company Sites Fetched Successfully!",
      sites,
    );
    return c.json(response, response.status as ContentfulStatusCode);
  },
  authMiddleware({
    permissions: ["company.fetch", "company.fetch.sites"],
  }),
);
