import { createRoute } from "../../modules/api-utils/createRoute";
import { apiResponse } from "../../modules/api-utils/apiResponse";
import { ContentfulStatusCode } from "hono/utils/http-status";
import { authMiddleware } from "../middleware/authorization";
import { getBoss } from "../../boss-instance";
import { WorkerQueue } from "../../modules/workers/queues";

/* POST /v1/cw/sync/full */
export default createRoute(
  "post",
  ["/sync/full"],
  async (c) => {
    const jobId = await getBoss().send(WorkerQueue.DALPURI_FULL_SYNC, {});

    if (!jobId) {
      throw new Error("Failed to enqueue dalpuri full sync job");
    }

    const response = apiResponse.successful(
      "Full sync enqueued successfully",
      { jobId }
    );
    return c.json(response, response.status as ContentfulStatusCode);
  },
  authMiddleware()
);
