/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v4-mini";
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 { EventSource, EventSource$inboundSchema } from "./eventsource.js";

export type EventName = {
  /**
   * The name of the event.
   */
  name: string;
  /**
   * Human readable label of the event.
   */
  label: string;
  source: EventSource;
  /**
   * Number of times the event has occurred.
   */
  occurrences: number;
  /**
   * The first time the event occurred.
   */
  firstSeen: Date;
  /**
   * The last time the event occurred.
   */
  lastSeen: Date;
};

/** @internal */
export const EventName$inboundSchema: z.ZodMiniType<EventName, unknown> = z
  .pipe(
    z.object({
      name: z.string(),
      label: z.string(),
      source: EventSource$inboundSchema,
      occurrences: z.int(),
      first_seen: z.pipe(
        z.iso.datetime({ offset: true }),
        z.transform(v => new Date(v)),
      ),
      last_seen: z.pipe(
        z.iso.datetime({ offset: true }),
        z.transform(v => new Date(v)),
      ),
    }),
    z.transform((v) => {
      return remap$(v, {
        "first_seen": "firstSeen",
        "last_seen": "lastSeen",
      });
    }),
  );

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