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

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

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

/**
 * Bad Request - A parameter was not specified, or was specified incorrectly.
 */
export type GetUsersBadRequestErrorData = {
  errors?: Array<operations.GetUsersBadRequestError> | 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 GetUsersBadRequestError extends PlexAPIError {
  errors?: Array<operations.GetUsersBadRequestError> | undefined;

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

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

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

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