/*
 * 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 GetTokenDetailsUnauthorizedErrorData = {
  errors?: Array<operations.GetTokenDetailsUnauthorizedError> | 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 GetTokenDetailsUnauthorizedError extends PlexAPIError {
  errors?: Array<operations.GetTokenDetailsUnauthorizedError> | undefined;

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

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

/**
 * Bad Request - A parameter was not specified, or was specified incorrectly.
 */
export type GetTokenDetailsBadRequestErrorData = {
  errors?: Array<operations.GetTokenDetailsBadRequestError> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;
};

/**
 * Bad Request - A parameter was not specified, or was specified incorrectly.
 */
export class GetTokenDetailsBadRequestError extends PlexAPIError {
  errors?: Array<operations.GetTokenDetailsBadRequestError> | undefined;

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

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

/** @internal */
export const GetTokenDetailsUnauthorizedError$inboundSchema: z.ZodType<
  GetTokenDetailsUnauthorizedError,
  z.ZodTypeDef,
  unknown
> = z.object({
  errors: z.array(
    z.lazy(() => operations.GetTokenDetailsUnauthorizedError$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 GetTokenDetailsUnauthorizedError(remapped, {
      request: v.request$,
      response: v.response$,
      body: v.body$,
    });
  });

/** @internal */
export const GetTokenDetailsBadRequestError$inboundSchema: z.ZodType<
  GetTokenDetailsBadRequestError,
  z.ZodTypeDef,
  unknown
> = z.object({
  errors: z.array(
    z.lazy(() => operations.GetTokenDetailsBadRequestError$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 GetTokenDetailsBadRequestError(remapped, {
      request: v.request$,
      response: v.response$,
      body: v.body$,
    });
  });
