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

import * as z from "zod/v3";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { ClosedEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  Access,
  Access$inboundSchema,
  Access$Outbound,
  Access$outboundSchema,
} from "./access.js";
import {
  AnalysisConfigRep,
  AnalysisConfigRep$inboundSchema,
  AnalysisConfigRep$Outbound,
  AnalysisConfigRep$outboundSchema,
} from "./analysisconfigrep.js";
import {
  IterationRep,
  IterationRep$inboundSchema,
  IterationRep$Outbound,
  IterationRep$outboundSchema,
} from "./iterationrep.js";
import {
  Link,
  Link$inboundSchema,
  Link$Outbound,
  Link$outboundSchema,
} from "./link.js";
import {
  MutableFieldsByStatusRep,
  MutableFieldsByStatusRep$inboundSchema,
  MutableFieldsByStatusRep$Outbound,
  MutableFieldsByStatusRep$outboundSchema,
} from "./mutablefieldsbystatusrep.js";

/**
 * The results analysis approach.
 */
export const ExperimentMethodology = {
  Bayesian: "bayesian",
  Frequentist: "frequentist",
  ExportOnly: "export_only",
} as const;
/**
 * The results analysis approach.
 */
export type ExperimentMethodology = ClosedEnum<typeof ExperimentMethodology>;

/**
 * The source of metric data in order to analyze results. Defaults to "launchdarkly" when not provided.
 */
export const ExperimentDataSource = {
  Launchdarkly: "launchdarkly",
  Snowflake: "snowflake",
} as const;
/**
 * The source of metric data in order to analyze results. Defaults to "launchdarkly" when not provided.
 */
export type ExperimentDataSource = ClosedEnum<typeof ExperimentDataSource>;

export type Experiment = {
  /**
   * The experiment ID
   */
  id?: string | undefined;
  /**
   * The experiment key
   */
  key: string;
  /**
   * The experiment name
   */
  name: string;
  /**
   * The experiment description
   */
  description?: string | undefined;
  /**
   * The ID of the member who maintains this experiment.
   */
  maintainerId: string;
  creationDate: number;
  environmentKey: string;
  /**
   * The results analysis approach.
   */
  methodology?: ExperimentMethodology | undefined;
  /**
   * The source of metric data in order to analyze results. Defaults to "launchdarkly" when not provided.
   */
  dataSource?: ExperimentDataSource | undefined;
  archivedDate?: number | undefined;
  /**
   * Tags for the experiment
   */
  tags?: Array<string> | undefined;
  /**
   * The location and content type of related resources
   */
  links: { [k: string]: Link };
  /**
   * The holdout ID
   */
  holdoutId?: string | undefined;
  currentIteration?: IterationRep | undefined;
  /**
   * The experiment type
   */
  type?: string | undefined;
  access?: Access | undefined;
  draftIteration?: IterationRep | undefined;
  /**
   * Details on the previous iterations for this experiment.
   */
  previousIterations?: Array<IterationRep> | undefined;
  analysisConfig?: AnalysisConfigRep | undefined;
  mutableFieldsByStatus?: MutableFieldsByStatusRep | undefined;
};

/** @internal */
export const ExperimentMethodology$inboundSchema: z.ZodNativeEnum<
  typeof ExperimentMethodology
> = z.nativeEnum(ExperimentMethodology);
/** @internal */
export const ExperimentMethodology$outboundSchema: z.ZodNativeEnum<
  typeof ExperimentMethodology
> = ExperimentMethodology$inboundSchema;

/** @internal */
export const ExperimentDataSource$inboundSchema: z.ZodNativeEnum<
  typeof ExperimentDataSource
> = z.nativeEnum(ExperimentDataSource);
/** @internal */
export const ExperimentDataSource$outboundSchema: z.ZodNativeEnum<
  typeof ExperimentDataSource
> = ExperimentDataSource$inboundSchema;

/** @internal */
export const Experiment$inboundSchema: z.ZodType<
  Experiment,
  z.ZodTypeDef,
  unknown
> = z.object({
  _id: z.string().optional(),
  key: z.string(),
  name: z.string(),
  description: z.string().optional(),
  _maintainerId: z.string(),
  _creationDate: z.number().int(),
  environmentKey: z.string(),
  methodology: ExperimentMethodology$inboundSchema.optional(),
  dataSource: ExperimentDataSource$inboundSchema.optional(),
  archivedDate: z.number().int().optional(),
  tags: z.array(z.string()).optional(),
  _links: z.record(Link$inboundSchema),
  holdoutId: z.string().optional(),
  currentIteration: IterationRep$inboundSchema.optional(),
  type: z.string().optional(),
  _access: Access$inboundSchema.optional(),
  draftIteration: IterationRep$inboundSchema.optional(),
  previousIterations: z.array(IterationRep$inboundSchema).optional(),
  analysisConfig: AnalysisConfigRep$inboundSchema.optional(),
  mutableFieldsByStatus: MutableFieldsByStatusRep$inboundSchema.optional(),
}).transform((v) => {
  return remap$(v, {
    "_id": "id",
    "_maintainerId": "maintainerId",
    "_creationDate": "creationDate",
    "_links": "links",
    "_access": "access",
  });
});
/** @internal */
export type Experiment$Outbound = {
  _id?: string | undefined;
  key: string;
  name: string;
  description?: string | undefined;
  _maintainerId: string;
  _creationDate: number;
  environmentKey: string;
  methodology?: string | undefined;
  dataSource?: string | undefined;
  archivedDate?: number | undefined;
  tags?: Array<string> | undefined;
  _links: { [k: string]: Link$Outbound };
  holdoutId?: string | undefined;
  currentIteration?: IterationRep$Outbound | undefined;
  type?: string | undefined;
  _access?: Access$Outbound | undefined;
  draftIteration?: IterationRep$Outbound | undefined;
  previousIterations?: Array<IterationRep$Outbound> | undefined;
  analysisConfig?: AnalysisConfigRep$Outbound | undefined;
  mutableFieldsByStatus?: MutableFieldsByStatusRep$Outbound | undefined;
};

/** @internal */
export const Experiment$outboundSchema: z.ZodType<
  Experiment$Outbound,
  z.ZodTypeDef,
  Experiment
> = z.object({
  id: z.string().optional(),
  key: z.string(),
  name: z.string(),
  description: z.string().optional(),
  maintainerId: z.string(),
  creationDate: z.number().int(),
  environmentKey: z.string(),
  methodology: ExperimentMethodology$outboundSchema.optional(),
  dataSource: ExperimentDataSource$outboundSchema.optional(),
  archivedDate: z.number().int().optional(),
  tags: z.array(z.string()).optional(),
  links: z.record(Link$outboundSchema),
  holdoutId: z.string().optional(),
  currentIteration: IterationRep$outboundSchema.optional(),
  type: z.string().optional(),
  access: Access$outboundSchema.optional(),
  draftIteration: IterationRep$outboundSchema.optional(),
  previousIterations: z.array(IterationRep$outboundSchema).optional(),
  analysisConfig: AnalysisConfigRep$outboundSchema.optional(),
  mutableFieldsByStatus: MutableFieldsByStatusRep$outboundSchema.optional(),
}).transform((v) => {
  return remap$(v, {
    id: "_id",
    maintainerId: "_maintainerId",
    creationDate: "_creationDate",
    links: "_links",
    access: "_access",
  });
});

export function experimentToJSON(experiment: Experiment): string {
  return JSON.stringify(Experiment$outboundSchema.parse(experiment));
}
export function experimentFromJSON(
  jsonString: string,
): SafeParseResult<Experiment, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Experiment$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Experiment' from JSON`,
  );
}
