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

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

export type PaymentMethodInUseByActiveSubscriptionData = {
  error: "PaymentMethodInUseByActiveSubscription";
  detail: string;
};

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

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

  constructor(
    err: PaymentMethodInUseByActiveSubscriptionData,
    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 = "PaymentMethodInUseByActiveSubscription";
  }
}

/** @internal */
export const PaymentMethodInUseByActiveSubscription$inboundSchema:
  z.ZodMiniType<PaymentMethodInUseByActiveSubscription, unknown> = z.pipe(
    z.object({
      error: z.literal("PaymentMethodInUseByActiveSubscription"),
      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 PaymentMethodInUseByActiveSubscription(v, {
        request: v.request$,
        response: v.response$,
        body: v.body$,
      });
    }),
  );
