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

export type RepositoryCollectionRep = {
  links: { [k: string]: Link };
  /**
   * An array of repositories
   */
  items: Array<RepositoryRep>;
};

/** @internal */
export const RepositoryCollectionRep$inboundSchema: z.ZodType<
  RepositoryCollectionRep,
  z.ZodTypeDef,
  unknown
> = z.object({
  _links: z.record(Link$inboundSchema),
  items: z.array(RepositoryRep$inboundSchema),
}).transform((v) => {
  return remap$(v, {
    "_links": "links",
  });
});
/** @internal */
export type RepositoryCollectionRep$Outbound = {
  _links: { [k: string]: Link$Outbound };
  items: Array<RepositoryRep$Outbound>;
};

/** @internal */
export const RepositoryCollectionRep$outboundSchema: z.ZodType<
  RepositoryCollectionRep$Outbound,
  z.ZodTypeDef,
  RepositoryCollectionRep
> = z.object({
  links: z.record(Link$outboundSchema),
  items: z.array(RepositoryRep$outboundSchema),
}).transform((v) => {
  return remap$(v, {
    links: "_links",
  });
});

export function repositoryCollectionRepToJSON(
  repositoryCollectionRep: RepositoryCollectionRep,
): string {
  return JSON.stringify(
    RepositoryCollectionRep$outboundSchema.parse(repositoryCollectionRep),
  );
}
export function repositoryCollectionRepFromJSON(
  jsonString: string,
): SafeParseResult<RepositoryCollectionRep, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => RepositoryCollectionRep$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'RepositoryCollectionRep' from JSON`,
  );
}
