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

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

export type NotPermittedData = {
  error: "NotPermitted";
  detail: string;
};

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

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

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

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