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

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 { smartUnion } from "../../types/smartUnion.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  ChatTranscriptionEvent,
  ChatTranscriptionEvent$inboundSchema,
} from "./chattranscriptionevent.js";

export type ChatCompletionEventExtraFields =
  | boolean
  | number
  | number
  | string
  | Date
  | Array<string>
  | { [k: string]: string };

export type ChatCompletionEvent = {
  eventId: string;
  correlationId: string;
  createdAt: Date;
  extraFields: {
    [k: string]: boolean | number | number | string | Date | Array<string> | {
      [k: string]: string;
    } | null;
  };
  nbInputTokens: number;
  nbOutputTokens: number;
  enabledTools: Array<{ [k: string]: any }>;
  requestMessages: Array<{ [k: string]: any }>;
  responseMessages: Array<{ [k: string]: any }>;
  nbMessages: number;
  chatTranscriptionEvents: Array<ChatTranscriptionEvent>;
};

/** @internal */
export const ChatCompletionEventExtraFields$inboundSchema: z.ZodType<
  ChatCompletionEventExtraFields,
  unknown
> = smartUnion([
  z.boolean(),
  z.int(),
  z.number(),
  z.string(),
  z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  z.array(z.string()),
  z.record(z.string(), z.string()),
]);

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

/** @internal */
export const ChatCompletionEvent$inboundSchema: z.ZodType<
  ChatCompletionEvent,
  unknown
> = z.object({
  event_id: z.string(),
  correlation_id: z.string(),
  created_at: z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  extra_fields: z.record(
    z.string(),
    z.nullable(
      smartUnion([
        z.boolean(),
        z.int(),
        z.number(),
        z.string(),
        z.iso.datetime({ offset: true }).transform(v => new Date(v)),
        z.array(z.string()),
        z.record(z.string(), z.string()),
      ]),
    ),
  ),
  nb_input_tokens: z.int(),
  nb_output_tokens: z.int(),
  enabled_tools: z.array(z.record(z.string(), z.any())),
  request_messages: z.array(z.record(z.string(), z.any())),
  response_messages: z.array(z.record(z.string(), z.any())),
  nb_messages: z.int(),
  chat_transcription_events: z.array(ChatTranscriptionEvent$inboundSchema),
}).transform((v) => {
  return remap$(v, {
    "event_id": "eventId",
    "correlation_id": "correlationId",
    "created_at": "createdAt",
    "extra_fields": "extraFields",
    "nb_input_tokens": "nbInputTokens",
    "nb_output_tokens": "nbOutputTokens",
    "enabled_tools": "enabledTools",
    "request_messages": "requestMessages",
    "response_messages": "responseMessages",
    "nb_messages": "nbMessages",
    "chat_transcription_events": "chatTranscriptionEvents",
  });
});

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