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

import * as z from "zod/v3";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type LayerSnapshotRep = {
  /**
   * Key of the layer the experiment was part of
   */
  key: string;
  /**
   * Layer name at the time this experiment iteration was stopped
   */
  name: string;
  /**
   * Percent of layer traffic that was reserved in the layer for this experiment iteration
   */
  reservationPercent: number;
  /**
   * Percent of layer traffic that was reserved for other experiments in the same environment, when this experiment iteration was stopped
   */
  otherReservationPercent: number;
};

/** @internal */
export const LayerSnapshotRep$inboundSchema: z.ZodType<
  LayerSnapshotRep,
  z.ZodTypeDef,
  unknown
> = z.object({
  key: z.string(),
  name: z.string(),
  reservationPercent: z.number().int(),
  otherReservationPercent: z.number().int(),
});
/** @internal */
export type LayerSnapshotRep$Outbound = {
  key: string;
  name: string;
  reservationPercent: number;
  otherReservationPercent: number;
};

/** @internal */
export const LayerSnapshotRep$outboundSchema: z.ZodType<
  LayerSnapshotRep$Outbound,
  z.ZodTypeDef,
  LayerSnapshotRep
> = z.object({
  key: z.string(),
  name: z.string(),
  reservationPercent: z.number().int(),
  otherReservationPercent: z.number().int(),
});

export function layerSnapshotRepToJSON(
  layerSnapshotRep: LayerSnapshotRep,
): string {
  return JSON.stringify(
    LayerSnapshotRep$outboundSchema.parse(layerSnapshotRep),
  );
}
export function layerSnapshotRepFromJSON(
  jsonString: string,
): SafeParseResult<LayerSnapshotRep, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => LayerSnapshotRep$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'LayerSnapshotRep' from JSON`,
  );
}
