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

export type EventOut = {
  /**
   * The name of the event.
   */
  name: string;
  data?: { [k: string]: any } | null | undefined;
  /**
   * The UNIX timestamp (in seconds) of the event.
   */
  createdAt: number;
};

/** @internal */
export const EventOut$inboundSchema: z.ZodType<
  EventOut,
  z.ZodTypeDef,
  unknown
> = z.object({
  name: z.string(),
  data: z.nullable(z.record(z.any())).optional(),
  created_at: z.number().int(),
}).transform((v) => {
  return remap$(v, {
    "created_at": "createdAt",
  });
});

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