import { ProjectDto } from "@montelo/browser-client";
import { ActionFunction, json } from "@remix-run/node";
import { withAuth } from "~/auth/withAuth";

export const action: ActionFunction = withAuth(async ({ api, request }) => {
  if (request.method === "POST") {
    const body = (await request.json()) as { key: string };
    const project = await api.project.projectControllerSetOpenAIAPIKey({
      setOpenaiApiKeyInput: body,
    });
    return json<{ project: ProjectDto }>({ project });
  }

  return json({});
});
