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

import * as z from "zod/v3";
import { remap as remap$ } from "../../../lib/primitives.js";
import * as operations from "../operations/index.js";
import { PlexAPIError } from "./plexapierror.js";

/**
 * Unauthorized - Returned if the X-Plex-Token is missing from the header or query.
 */
export type GetServerResourcesUnauthorizedErrorData = {
  errors?: Array<operations.GetServerResourcesError> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;
};

/**
 * Unauthorized - Returned if the X-Plex-Token is missing from the header or query.
 */
export class GetServerResourcesUnauthorizedError extends PlexAPIError {
  errors?: Array<operations.GetServerResourcesError> | undefined;

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

  constructor(
    err: GetServerResourcesUnauthorizedErrorData,
    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.errors != null) this.errors = err.errors;

    this.name = "GetServerResourcesUnauthorizedError";
  }
}

/** @internal */
export const GetServerResourcesUnauthorizedError$inboundSchema: z.ZodType<
  GetServerResourcesUnauthorizedError,
  z.ZodTypeDef,
  unknown
> = z.object({
  errors: z.array(
    z.lazy(() => operations.GetServerResourcesError$inboundSchema),
  ).optional(),
  RawResponse: z.instanceof(Response).optional(),
  request$: z.instanceof(Request),
  response$: z.instanceof(Response),
  body$: z.string(),
})
  .transform((v) => {
    const remapped = remap$(v, {
      "RawResponse": "rawResponse",
    });

    return new GetServerResourcesUnauthorizedError(remapped, {
      request: v.request$,
      response: v.response$,
      body: v.body$,
    });
  });
