/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import { experimentsCreate } from "../../funcs/experimentsCreate.js";
import * as operations from "../../models/operations/index.js";
import { formatResult, ToolDefinition } from "../tools.js";

const args = {
  request: operations.CreateExperimentRequest$inboundSchema,
};

export const tool$experimentsCreate: ToolDefinition<typeof args> = {
  name: "create-experiment",
  description:
    `Creates an experiment in a project environment, with an initial iteration that sets the hypothesis, flag, treatments, and metrics.`,
  scopes: ["write"],
  args,
  tool: async (client, args, ctx) => {
    const [result, apiCall] = await experimentsCreate(
      client,
      args.request,
      { fetchOptions: { signal: ctx.signal } },
    ).$inspect();

    if (!result.ok) {
      return {
        content: [{ type: "text", text: result.error.message }],
        isError: true,
      };
    }

    const value = result.value;

    return formatResult(value, apiCall);
  },
};
