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

import * as z from "zod/v3";
import * as components from "../components/index.js";
import { MistralError } from "./mistralerror.js";

export type HTTPValidationErrorData = {
  detail?: Array<components.ValidationError> | undefined;
};

export class HTTPValidationError extends MistralError {
  detail?: Array<components.ValidationError> | undefined;

  /** The original data that was passed to this error instance. */
  data$: HTTPValidationErrorData;

  constructor(
    err: HTTPValidationErrorData,
    httpMeta: { response: Response; request: Request; body: string },
  ) {
    const message = "message" in err && typeof err.message === "string"
      ? err.message
      : `API error occurred: ${JSON.stringify(err)}`;
    super(message, httpMeta);
    this.data$ = err;
    if (err.detail != null) this.detail = err.detail;

    this.name = "HTTPValidationError";
  }
}

/** @internal */
export const HTTPValidationError$inboundSchema: z.ZodType<
  HTTPValidationError,
  z.ZodTypeDef,
  unknown
> = z.object({
  detail: z.array(components.ValidationError$inboundSchema).optional(),
  request$: z.instanceof(Request),
  response$: z.instanceof(Response),
  body$: z.string(),
})
  .transform((v) => {
    return new HTTPValidationError(v, {
      request: v.request$,
      response: v.response$,
      body: v.body$,
    });
  });
