/*
 * 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 {
  ConversationUsageInfo,
  ConversationUsageInfo$inboundSchema,
} from "./conversationusageinfo.js";

export type ResponseDoneEvent = {
  type?: "conversation.response.done" | undefined;
  createdAt?: Date | undefined;
  usage: ConversationUsageInfo;
};

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

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