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

/* /v1/schedule/schedules/:identifier */
export default createRoute(
  "get",
  ["/schedules/:identifier"],
  async (c) => {
    const schedule = await schedules.fetch(c.req.param("identifier"));

    const response = apiResponse.successful(
      "Schedule Fetched Successfully!",
      schedule.toJson(),
    );

    return c.json(response, response.status as ContentfulStatusCode);
  },
  authMiddleware({ permissions: ["schedule.fetch"] }),
);
