import { ActionFunction, json } from "@remix-run/node";
import { withAuth } from "~/auth/withAuth";
import { StartFineTuneAction, StartMonteloFineTuneBody } from "~/types/StartFineTuneAction.types";

export const action: ActionFunction = withAuth(async ({ api, params, request }) => {
  if (request.method === "POST") {
    const datasetId = params.datasetId!;
    const body = (await request.json()) as StartMonteloFineTuneBody;
    const finetuneJob = await api.fineTuning.finetuneControllerCreateFineTune({
      datasetId,
      createFineTuneInput: body,
    });
    return json<StartFineTuneAction>({ finetune: finetuneJob });
  }

  return json({});
});
