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

import * as z from "zod/v4-mini";
import { PolarError } from "./polarerror.js";

export type PaymentErrorData = {
  error: "PaymentError";
  detail: string;
};

export class PaymentError extends PolarError {
  error: "PaymentError";
  detail: string;

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

  constructor(
    err: PaymentErrorData,
    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;
    this.error = err.error;
    this.detail = err.detail;

    this.name = "PaymentError";
  }
}

/** @internal */
export const PaymentError$inboundSchema: z.ZodMiniType<PaymentError, unknown> =
  z.pipe(
    z.object({
      error: z.literal("PaymentError"),
      detail: z.string(),
      request$: z.custom<Request>(x => x instanceof Request),
      response$: z.custom<Response>(x => x instanceof Response),
      body$: z.string(),
    }),
    z.transform((v) => {
      return new PaymentError(v, {
        request: v.request$,
        response: v.response$,
        body: v.body$,
      });
    }),
  );
