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

import * as z from "zod";
import { remap as remap$ } from "../../../lib/primitives.js";

export type GetGlobalHubsHubsErrors = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

/**
 * Unauthorized - Returned if the X-Plex-Token is missing from the header or query.
 */
export type GetGlobalHubsUnauthorizedData = {
  errors?: Array<GetGlobalHubsHubsErrors> | 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 GetGlobalHubsUnauthorized extends Error {
  errors?: Array<GetGlobalHubsHubsErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

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

  constructor(err: GetGlobalHubsUnauthorizedData) {
    const message = "message" in err && typeof err.message === "string"
      ? err.message
      : `API error occurred: ${JSON.stringify(err)}`;
    super(message);
    this.data$ = err;

    if (err.errors != null) this.errors = err.errors;
    if (err.rawResponse != null) this.rawResponse = err.rawResponse;

    this.name = "GetGlobalHubsUnauthorized";
  }
}

export type GetGlobalHubsErrors = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

/**
 * Bad Request - A parameter was not specified, or was specified incorrectly.
 */
export type GetGlobalHubsBadRequestData = {
  errors?: Array<GetGlobalHubsErrors> | 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 GetGlobalHubsBadRequest extends Error {
  errors?: Array<GetGlobalHubsErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

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

  constructor(err: GetGlobalHubsBadRequestData) {
    const message = "message" in err && typeof err.message === "string"
      ? err.message
      : `API error occurred: ${JSON.stringify(err)}`;
    super(message);
    this.data$ = err;

    if (err.errors != null) this.errors = err.errors;
    if (err.rawResponse != null) this.rawResponse = err.rawResponse;

    this.name = "GetGlobalHubsBadRequest";
  }
}

/** @internal */
export const GetGlobalHubsHubsErrors$inboundSchema: z.ZodType<
  GetGlobalHubsHubsErrors,
  z.ZodTypeDef,
  unknown
> = z.object({
  code: z.number().int().optional(),
  message: z.string().optional(),
  status: z.number().int().optional(),
});

/** @internal */
export type GetGlobalHubsHubsErrors$Outbound = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

/** @internal */
export const GetGlobalHubsHubsErrors$outboundSchema: z.ZodType<
  GetGlobalHubsHubsErrors$Outbound,
  z.ZodTypeDef,
  GetGlobalHubsHubsErrors
> = z.object({
  code: z.number().int().optional(),
  message: z.string().optional(),
  status: z.number().int().optional(),
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace GetGlobalHubsHubsErrors$ {
  /** @deprecated use `GetGlobalHubsHubsErrors$inboundSchema` instead. */
  export const inboundSchema = GetGlobalHubsHubsErrors$inboundSchema;
  /** @deprecated use `GetGlobalHubsHubsErrors$outboundSchema` instead. */
  export const outboundSchema = GetGlobalHubsHubsErrors$outboundSchema;
  /** @deprecated use `GetGlobalHubsHubsErrors$Outbound` instead. */
  export type Outbound = GetGlobalHubsHubsErrors$Outbound;
}

/** @internal */
export const GetGlobalHubsUnauthorized$inboundSchema: z.ZodType<
  GetGlobalHubsUnauthorized,
  z.ZodTypeDef,
  unknown
> = z.object({
  errors: z.array(z.lazy(() => GetGlobalHubsHubsErrors$inboundSchema))
    .optional(),
  RawResponse: z.instanceof(Response).optional(),
})
  .transform((v) => {
    const remapped = remap$(v, {
      "RawResponse": "rawResponse",
    });

    return new GetGlobalHubsUnauthorized(remapped);
  });

/** @internal */
export type GetGlobalHubsUnauthorized$Outbound = {
  errors?: Array<GetGlobalHubsHubsErrors$Outbound> | undefined;
  RawResponse?: never | undefined;
};

/** @internal */
export const GetGlobalHubsUnauthorized$outboundSchema: z.ZodType<
  GetGlobalHubsUnauthorized$Outbound,
  z.ZodTypeDef,
  GetGlobalHubsUnauthorized
> = z.instanceof(GetGlobalHubsUnauthorized)
  .transform(v => v.data$)
  .pipe(
    z.object({
      errors: z.array(z.lazy(() => GetGlobalHubsHubsErrors$outboundSchema))
        .optional(),
      rawResponse: z.instanceof(Response).transform(() => {
        throw new Error("Response cannot be serialized");
      }).optional(),
    }).transform((v) => {
      return remap$(v, {
        rawResponse: "RawResponse",
      });
    }),
  );

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace GetGlobalHubsUnauthorized$ {
  /** @deprecated use `GetGlobalHubsUnauthorized$inboundSchema` instead. */
  export const inboundSchema = GetGlobalHubsUnauthorized$inboundSchema;
  /** @deprecated use `GetGlobalHubsUnauthorized$outboundSchema` instead. */
  export const outboundSchema = GetGlobalHubsUnauthorized$outboundSchema;
  /** @deprecated use `GetGlobalHubsUnauthorized$Outbound` instead. */
  export type Outbound = GetGlobalHubsUnauthorized$Outbound;
}

/** @internal */
export const GetGlobalHubsErrors$inboundSchema: z.ZodType<
  GetGlobalHubsErrors,
  z.ZodTypeDef,
  unknown
> = z.object({
  code: z.number().int().optional(),
  message: z.string().optional(),
  status: z.number().int().optional(),
});

/** @internal */
export type GetGlobalHubsErrors$Outbound = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

/** @internal */
export const GetGlobalHubsErrors$outboundSchema: z.ZodType<
  GetGlobalHubsErrors$Outbound,
  z.ZodTypeDef,
  GetGlobalHubsErrors
> = z.object({
  code: z.number().int().optional(),
  message: z.string().optional(),
  status: z.number().int().optional(),
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace GetGlobalHubsErrors$ {
  /** @deprecated use `GetGlobalHubsErrors$inboundSchema` instead. */
  export const inboundSchema = GetGlobalHubsErrors$inboundSchema;
  /** @deprecated use `GetGlobalHubsErrors$outboundSchema` instead. */
  export const outboundSchema = GetGlobalHubsErrors$outboundSchema;
  /** @deprecated use `GetGlobalHubsErrors$Outbound` instead. */
  export type Outbound = GetGlobalHubsErrors$Outbound;
}

/** @internal */
export const GetGlobalHubsBadRequest$inboundSchema: z.ZodType<
  GetGlobalHubsBadRequest,
  z.ZodTypeDef,
  unknown
> = z.object({
  errors: z.array(z.lazy(() => GetGlobalHubsErrors$inboundSchema)).optional(),
  RawResponse: z.instanceof(Response).optional(),
})
  .transform((v) => {
    const remapped = remap$(v, {
      "RawResponse": "rawResponse",
    });

    return new GetGlobalHubsBadRequest(remapped);
  });

/** @internal */
export type GetGlobalHubsBadRequest$Outbound = {
  errors?: Array<GetGlobalHubsErrors$Outbound> | undefined;
  RawResponse?: never | undefined;
};

/** @internal */
export const GetGlobalHubsBadRequest$outboundSchema: z.ZodType<
  GetGlobalHubsBadRequest$Outbound,
  z.ZodTypeDef,
  GetGlobalHubsBadRequest
> = z.instanceof(GetGlobalHubsBadRequest)
  .transform(v => v.data$)
  .pipe(
    z.object({
      errors: z.array(z.lazy(() => GetGlobalHubsErrors$outboundSchema))
        .optional(),
      rawResponse: z.instanceof(Response).transform(() => {
        throw new Error("Response cannot be serialized");
      }).optional(),
    }).transform((v) => {
      return remap$(v, {
        rawResponse: "RawResponse",
      });
    }),
  );

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace GetGlobalHubsBadRequest$ {
  /** @deprecated use `GetGlobalHubsBadRequest$inboundSchema` instead. */
  export const inboundSchema = GetGlobalHubsBadRequest$inboundSchema;
  /** @deprecated use `GetGlobalHubsBadRequest$outboundSchema` instead. */
  export const outboundSchema = GetGlobalHubsBadRequest$outboundSchema;
  /** @deprecated use `GetGlobalHubsBadRequest$Outbound` instead. */
  export type Outbound = GetGlobalHubsBadRequest$Outbound;
}
