/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: 638baed27456
 */

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

export type ObservabilityErrorData = {
  detail: components.ObservabilityErrorDetail;
};

export class ObservabilityError extends MistralError {
  detail: components.ObservabilityErrorDetail;

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

  constructor(
    err: ObservabilityErrorData,
    httpMeta: { response: Response; request: Request; body: string },
  ) {
    const message = err.detail?.message
      || `API error occurred: ${JSON.stringify(err)}`;
    super(message, httpMeta);
    this.data$ = err;
    this.detail = err.detail;

    this.name = "ObservabilityError";
  }
}

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