/*
 * 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 * as components from "../components/index.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type AgentsApiV1ConversationsListRequest = {
  page?: number | undefined;
  pageSize?: number | undefined;
  metadata?: { [k: string]: any } | null | undefined;
};

export type ResponseBody =
  | components.ModelConversation
  | components.AgentConversation;

/** @internal */
export type AgentsApiV1ConversationsListRequest$Outbound = {
  page: number;
  page_size: number;
  metadata?: { [k: string]: any } | null | undefined;
};

/** @internal */
export const AgentsApiV1ConversationsListRequest$outboundSchema: z.ZodType<
  AgentsApiV1ConversationsListRequest$Outbound,
  z.ZodTypeDef,
  AgentsApiV1ConversationsListRequest
> = z.object({
  page: z.number().int().default(0),
  pageSize: z.number().int().default(100),
  metadata: z.nullable(z.record(z.any())).optional(),
}).transform((v) => {
  return remap$(v, {
    pageSize: "page_size",
  });
});

export function agentsApiV1ConversationsListRequestToJSON(
  agentsApiV1ConversationsListRequest: AgentsApiV1ConversationsListRequest,
): string {
  return JSON.stringify(
    AgentsApiV1ConversationsListRequest$outboundSchema.parse(
      agentsApiV1ConversationsListRequest,
    ),
  );
}

/** @internal */
export const ResponseBody$inboundSchema: z.ZodType<
  ResponseBody,
  z.ZodTypeDef,
  unknown
> = z.union([
  components.ModelConversation$inboundSchema,
  components.AgentConversation$inboundSchema,
]);

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