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

  return json({});
});
