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

export const ResponseStartedEventType = {
  ConversationResponseStarted: "conversation.response.started",
} as const;
export type ResponseStartedEventType = ClosedEnum<
  typeof ResponseStartedEventType
>;

export type ResponseStartedEvent = {
  type: ResponseStartedEventType | undefined;
  createdAt?: Date | undefined;
  conversationId: string;
};

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

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

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