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

import * as z from "zod/v3";
import { Unrecognized, unrecognized } from "./unrecognized.js";

export type ClosedEnum<T extends Readonly<Record<string, string | number>>> =
  T[keyof T];
export type OpenEnum<T extends Readonly<Record<string, string | number>>> =
  | T[keyof T]
  | Unrecognized<T[keyof T] extends number ? number : string>;

export function inboundSchema<T extends Record<string, string>>(
  enumObj: T,
): z.ZodType<OpenEnum<T>, z.ZodTypeDef, unknown> {
  const options = Object.values(enumObj);
  return z.union([
    ...options.map(x => z.literal(x)),
    z.string().transform(x => unrecognized(x)),
  ] as any);
}

export function inboundSchemaInt<T extends Record<string, number | string>>(
  enumObj: T,
): z.ZodType<OpenEnum<T>, z.ZodTypeDef, unknown> {
  // For numeric enums, Object.values returns both numbers and string keys
  const options = Object.values(enumObj).filter(v => typeof v === "number");
  return z.union([
    ...options.map(x => z.literal(x)),
    z.number().int().transform(x => unrecognized(x)),
  ] as any);
}

export function outboundSchema<T extends Record<string, string>>(
  _: T,
): z.ZodType<string, z.ZodTypeDef, OpenEnum<T>> {
  return z.string() as any;
}

export function outboundSchemaInt<T extends Record<string, number | string>>(
  _: T,
): z.ZodType<number, z.ZodTypeDef, OpenEnum<T>> {
  return z.number().int() as any;
}
