import { ActionFunction, json } from "@remix-run/node";
import { withAuth } from "~/auth/withAuth";
import { StartFineTuneAction, StartFineTuneBody } 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 StartFineTuneBody;
    const finetuneJob = await api.fineTuning.fineTuningControllerCreateOpenAI({
      datasetId,
      fineTuneOpenaiInput: body,
    });
    return json<StartFineTuneAction>({ finetune: finetuneJob });
  }

  return json({});
});
