/*
 * 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 {
  Experiment,
  Experiment$inboundSchema,
  Experiment$Outbound,
  Experiment$outboundSchema,
} from "./experiment.js";
import {
  Link,
  Link$inboundSchema,
  Link$Outbound,
  Link$outboundSchema,
} from "./link.js";

export type ExperimentCollectionRep = {
  /**
   * An array of experiments
   */
  items: Array<Experiment>;
  /**
   * The total number of experiments in this project and environment. Does not include legacy experiments.
   */
  totalCount?: number | undefined;
  /**
   * The location and content type of related resources
   */
  links?: { [k: string]: Link } | undefined;
};

/** @internal */
export const ExperimentCollectionRep$inboundSchema: z.ZodType<
  ExperimentCollectionRep,
  z.ZodTypeDef,
  unknown
> = z.object({
  items: z.array(Experiment$inboundSchema),
  total_count: z.number().int().optional(),
  _links: z.record(Link$inboundSchema).optional(),
}).transform((v) => {
  return remap$(v, {
    "total_count": "totalCount",
    "_links": "links",
  });
});
/** @internal */
export type ExperimentCollectionRep$Outbound = {
  items: Array<Experiment$Outbound>;
  total_count?: number | undefined;
  _links?: { [k: string]: Link$Outbound } | undefined;
};

/** @internal */
export const ExperimentCollectionRep$outboundSchema: z.ZodType<
  ExperimentCollectionRep$Outbound,
  z.ZodTypeDef,
  ExperimentCollectionRep
> = z.object({
  items: z.array(Experiment$outboundSchema),
  totalCount: z.number().int().optional(),
  links: z.record(Link$outboundSchema).optional(),
}).transform((v) => {
  return remap$(v, {
    totalCount: "total_count",
    links: "_links",
  });
});

export function experimentCollectionRepToJSON(
  experimentCollectionRep: ExperimentCollectionRep,
): string {
  return JSON.stringify(
    ExperimentCollectionRep$outboundSchema.parse(experimentCollectionRep),
  );
}
export function experimentCollectionRepFromJSON(
  jsonString: string,
): SafeParseResult<ExperimentCollectionRep, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ExperimentCollectionRep$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ExperimentCollectionRep' from JSON`,
  );
}
