/*
 * 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";

export type ResponseErrorEvent = {
  type?: "conversation.response.error" | undefined;
  createdAt?: Date | undefined;
  message: string;
  code: number;
};

/** @internal */
export const ResponseErrorEvent$inboundSchema: z.ZodType<
  ResponseErrorEvent,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: z.literal("conversation.response.error").default(
    "conversation.response.error",
  ),
  created_at: z.string().datetime({ offset: true }).transform(v => new Date(v))
    .optional(),
  message: z.string(),
  code: z.number().int(),
}).transform((v) => {
  return remap$(v, {
    "created_at": "createdAt",
  });
});

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