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

import * as z from "zod/v3";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type Loc = string | number;

export type ValidationError = {
  loc: Array<string | number>;
  msg: string;
  type: string;
};

/** @internal */
export const Loc$inboundSchema: z.ZodType<Loc, z.ZodTypeDef, unknown> = z.union(
  [z.string(), z.number().int()],
);

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 ValidationError$inboundSchema: z.ZodType<
  ValidationError,
  z.ZodTypeDef,
  unknown
> = z.object({
  loc: z.array(z.union([z.string(), z.number().int()])),
  msg: z.string(),
  type: z.string(),
});

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