/*
 * 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 { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  ExperimentEnvironmentSettingRep,
  ExperimentEnvironmentSettingRep$inboundSchema,
  ExperimentEnvironmentSettingRep$Outbound,
  ExperimentEnvironmentSettingRep$outboundSchema,
} from "./experimentenvironmentsettingrep.js";
import {
  MetricListingRep,
  MetricListingRep$inboundSchema,
  MetricListingRep$Outbound,
  MetricListingRep$outboundSchema,
} from "./metriclistingrep.js";

export type LegacyExperimentRep = {
  metricKey?: string | undefined;
  metric?: MetricListingRep | undefined;
  environments?: Array<string> | undefined;
  environmentSettings?:
    | { [k: string]: ExperimentEnvironmentSettingRep }
    | undefined;
};

/** @internal */
export const LegacyExperimentRep$inboundSchema: z.ZodType<
  LegacyExperimentRep,
  z.ZodTypeDef,
  unknown
> = z.object({
  metricKey: z.string().optional(),
  _metric: MetricListingRep$inboundSchema.optional(),
  environments: z.array(z.string()).optional(),
  _environmentSettings: z.record(ExperimentEnvironmentSettingRep$inboundSchema)
    .optional(),
}).transform((v) => {
  return remap$(v, {
    "_metric": "metric",
    "_environmentSettings": "environmentSettings",
  });
});
/** @internal */
export type LegacyExperimentRep$Outbound = {
  metricKey?: string | undefined;
  _metric?: MetricListingRep$Outbound | undefined;
  environments?: Array<string> | undefined;
  _environmentSettings?: {
    [k: string]: ExperimentEnvironmentSettingRep$Outbound;
  } | undefined;
};

/** @internal */
export const LegacyExperimentRep$outboundSchema: z.ZodType<
  LegacyExperimentRep$Outbound,
  z.ZodTypeDef,
  LegacyExperimentRep
> = z.object({
  metricKey: z.string().optional(),
  metric: MetricListingRep$outboundSchema.optional(),
  environments: z.array(z.string()).optional(),
  environmentSettings: z.record(ExperimentEnvironmentSettingRep$outboundSchema)
    .optional(),
}).transform((v) => {
  return remap$(v, {
    metric: "_metric",
    environmentSettings: "_environmentSettings",
  });
});

export function legacyExperimentRepToJSON(
  legacyExperimentRep: LegacyExperimentRep,
): string {
  return JSON.stringify(
    LegacyExperimentRep$outboundSchema.parse(legacyExperimentRep),
  );
}
export function legacyExperimentRepFromJSON(
  jsonString: string,
): SafeParseResult<LegacyExperimentRep, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => LegacyExperimentRep$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'LegacyExperimentRep' from JSON`,
  );
}
