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

import * as z from "zod";
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 {
  Agreement,
  Agreement$inboundSchema,
  Agreement$Outbound,
  Agreement$outboundSchema,
} from "./agreement.js";
import {
  ResponseMetadata,
  ResponseMetadata$inboundSchema,
  ResponseMetadata$Outbound,
  ResponseMetadata$outboundSchema,
} from "./responsemetadata.js";

/**
 * A collection of agreements.
 */
export type AgreementsResponse = {
  /**
   * A list of agreements
   */
  data?: Array<Agreement> | undefined;
  /**
   * Control information and metadata for the response.
   */
  responseMetadata?: ResponseMetadata | undefined;
};

/** @internal */
export const AgreementsResponse$inboundSchema: z.ZodType<
  AgreementsResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  data: z.array(Agreement$inboundSchema).optional(),
  response_metadata: ResponseMetadata$inboundSchema.optional(),
}).transform((v) => {
  return remap$(v, {
    "response_metadata": "responseMetadata",
  });
});

/** @internal */
export type AgreementsResponse$Outbound = {
  data?: Array<Agreement$Outbound> | undefined;
  response_metadata?: ResponseMetadata$Outbound | undefined;
};

/** @internal */
export const AgreementsResponse$outboundSchema: z.ZodType<
  AgreementsResponse$Outbound,
  z.ZodTypeDef,
  AgreementsResponse
> = z.object({
  data: z.array(Agreement$outboundSchema).optional(),
  responseMetadata: ResponseMetadata$outboundSchema.optional(),
}).transform((v) => {
  return remap$(v, {
    responseMetadata: "response_metadata",
  });
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace AgreementsResponse$ {
  /** @deprecated use `AgreementsResponse$inboundSchema` instead. */
  export const inboundSchema = AgreementsResponse$inboundSchema;
  /** @deprecated use `AgreementsResponse$outboundSchema` instead. */
  export const outboundSchema = AgreementsResponse$outboundSchema;
  /** @deprecated use `AgreementsResponse$Outbound` instead. */
  export type Outbound = AgreementsResponse$Outbound;
}

export function agreementsResponseToJSON(
  agreementsResponse: AgreementsResponse,
): string {
  return JSON.stringify(
    AgreementsResponse$outboundSchema.parse(agreementsResponse),
  );
}

export function agreementsResponseFromJSON(
  jsonString: string,
): SafeParseResult<AgreementsResponse, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => AgreementsResponse$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'AgreementsResponse' from JSON`,
  );
}
