/*
 * 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 { ClosedEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  ConversationUsageInfo,
  ConversationUsageInfo$inboundSchema,
} from "./conversationusageinfo.js";

export const ResponseDoneEventType = {
  ConversationResponseDone: "conversation.response.done",
} as const;
export type ResponseDoneEventType = ClosedEnum<typeof ResponseDoneEventType>;

export type ResponseDoneEvent = {
  type: ResponseDoneEventType | undefined;
  createdAt?: Date | undefined;
  usage: ConversationUsageInfo;
};

/** @internal */
export const ResponseDoneEventType$inboundSchema: z.ZodNativeEnum<
  typeof ResponseDoneEventType
> = z.nativeEnum(ResponseDoneEventType);

/** @internal */
export const ResponseDoneEvent$inboundSchema: z.ZodType<
  ResponseDoneEvent,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: ResponseDoneEventType$inboundSchema.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`,
  );
}
