import { DatapointDto } from "@montelo/browser-client";
import { ActionFunction, json } from "@remix-run/node";
import { withAuth } from "~/auth/withAuth";
import { CreateDatapointActionTypes } from "~/types/CreateDatapointAction.types";

export const action: ActionFunction = withAuth(async ({ api, request, params }) => {
  const data = (await request.json()) as CreateDatapointActionTypes;
  const datapoint = await api.datapoint.datapointControllerCreateDatapoint({
    datasetId: data.datasetId,
    addToDatasetInput: {
      input: data.input,
      expectedOutput: data.expectedOutput,
      source: data.source,
      sourceId: data.sourceId,
    },
  });
  return json<{ datapoint: DatapointDto }>({ datapoint });
});
