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

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

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

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

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

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

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

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