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

import * as z from "zod/v4-mini";
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";

export type Loc = string | number;

export type Context = {};

export type ValidationError = {
  loc: Array<string | number>;
  msg: string;
  type: string;
  input?: any | undefined;
  ctx?: Context | undefined;
};

/** @internal */
export const Loc$inboundSchema: z.ZodMiniType<Loc, unknown> = smartUnion([
  z.string(),
  z.int(),
]);
/** @internal */
export type Loc$Outbound = string | number;

/** @internal */
export const Loc$outboundSchema: z.ZodMiniType<Loc$Outbound, Loc> = smartUnion([
  z.string(),
  z.int(),
]);

export function locToJSON(loc: Loc): string {
  return JSON.stringify(Loc$outboundSchema.parse(loc));
}
export function locFromJSON(
  jsonString: string,
): SafeParseResult<Loc, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Loc$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Loc' from JSON`,
  );
}

/** @internal */
export const Context$inboundSchema: z.ZodMiniType<Context, unknown> = z.object(
  {},
);
/** @internal */
export type Context$Outbound = {};

/** @internal */
export const Context$outboundSchema: z.ZodMiniType<Context$Outbound, Context> =
  z.object({});

export function contextToJSON(context: Context): string {
  return JSON.stringify(Context$outboundSchema.parse(context));
}
export function contextFromJSON(
  jsonString: string,
): SafeParseResult<Context, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Context$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Context' from JSON`,
  );
}

/** @internal */
export const ValidationError$inboundSchema: z.ZodMiniType<
  ValidationError,
  unknown
> = z.object({
  loc: z.array(smartUnion([z.string(), z.int()])),
  msg: z.string(),
  type: z.string(),
  input: z.optional(z.any()),
  ctx: z.optional(z.lazy(() => Context$inboundSchema)),
});
/** @internal */
export type ValidationError$Outbound = {
  loc: Array<string | number>;
  msg: string;
  type: string;
  input?: any | undefined;
  ctx?: Context$Outbound | undefined;
};

/** @internal */
export const ValidationError$outboundSchema: z.ZodMiniType<
  ValidationError$Outbound,
  ValidationError
> = z.object({
  loc: z.array(smartUnion([z.string(), z.int()])),
  msg: z.string(),
  type: z.string(),
  input: z.optional(z.any()),
  ctx: z.optional(z.lazy(() => Context$outboundSchema)),
});

export function validationErrorToJSON(
  validationError: ValidationError,
): string {
  return JSON.stringify(ValidationError$outboundSchema.parse(validationError));
}
export function validationErrorFromJSON(
  jsonString: string,
): SafeParseResult<ValidationError, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ValidationError$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ValidationError' from JSON`,
  );
}
