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

import * as z from "zod/v4";
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";
  createdAt?: Date | undefined;
  message: string;
  code: number;
};

/** @internal */
export const ResponseErrorEvent$inboundSchema: z.ZodType<
  ResponseErrorEvent,
  unknown
> = z.object({
  type: z.literal("conversation.response.error"),
  created_at: z.iso.datetime({ offset: true }).transform(v => new Date(v))
    .optional(),
  message: z.string(),
  code: z.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`,
  );
}
