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

import * as z from "zod";
import { remap as remap$ } from "../../../lib/primitives.js";
import { safeParse } from "../../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

export type GetLibraryHubsHubsErrors = {
  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 GetLibraryHubsUnauthorizedData = {
  errors?: Array<GetLibraryHubsHubsErrors> | 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 GetLibraryHubsUnauthorized extends Error {
  errors?: Array<GetLibraryHubsHubsErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

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

  constructor(err: GetLibraryHubsUnauthorizedData) {
    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 = "GetLibraryHubsUnauthorized";
  }
}

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

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

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

  constructor(err: GetLibraryHubsBadRequestData) {
    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 = "GetLibraryHubsBadRequest";
  }
}

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

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

/** @internal */
export const GetLibraryHubsHubsErrors$outboundSchema: z.ZodType<
  GetLibraryHubsHubsErrors$Outbound,
  z.ZodTypeDef,
  GetLibraryHubsHubsErrors
> = 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 GetLibraryHubsHubsErrors$ {
  /** @deprecated use `GetLibraryHubsHubsErrors$inboundSchema` instead. */
  export const inboundSchema = GetLibraryHubsHubsErrors$inboundSchema;
  /** @deprecated use `GetLibraryHubsHubsErrors$outboundSchema` instead. */
  export const outboundSchema = GetLibraryHubsHubsErrors$outboundSchema;
  /** @deprecated use `GetLibraryHubsHubsErrors$Outbound` instead. */
  export type Outbound = GetLibraryHubsHubsErrors$Outbound;
}

export function getLibraryHubsHubsErrorsToJSON(
  getLibraryHubsHubsErrors: GetLibraryHubsHubsErrors,
): string {
  return JSON.stringify(
    GetLibraryHubsHubsErrors$outboundSchema.parse(getLibraryHubsHubsErrors),
  );
}

export function getLibraryHubsHubsErrorsFromJSON(
  jsonString: string,
): SafeParseResult<GetLibraryHubsHubsErrors, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => GetLibraryHubsHubsErrors$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'GetLibraryHubsHubsErrors' from JSON`,
  );
}

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

    return new GetLibraryHubsUnauthorized(remapped);
  });

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

/** @internal */
export const GetLibraryHubsUnauthorized$outboundSchema: z.ZodType<
  GetLibraryHubsUnauthorized$Outbound,
  z.ZodTypeDef,
  GetLibraryHubsUnauthorized
> = z.instanceof(GetLibraryHubsUnauthorized)
  .transform(v => v.data$)
  .pipe(
    z.object({
      errors: z.array(z.lazy(() => GetLibraryHubsHubsErrors$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 GetLibraryHubsUnauthorized$ {
  /** @deprecated use `GetLibraryHubsUnauthorized$inboundSchema` instead. */
  export const inboundSchema = GetLibraryHubsUnauthorized$inboundSchema;
  /** @deprecated use `GetLibraryHubsUnauthorized$outboundSchema` instead. */
  export const outboundSchema = GetLibraryHubsUnauthorized$outboundSchema;
  /** @deprecated use `GetLibraryHubsUnauthorized$Outbound` instead. */
  export type Outbound = GetLibraryHubsUnauthorized$Outbound;
}

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

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

/** @internal */
export const GetLibraryHubsErrors$outboundSchema: z.ZodType<
  GetLibraryHubsErrors$Outbound,
  z.ZodTypeDef,
  GetLibraryHubsErrors
> = 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 GetLibraryHubsErrors$ {
  /** @deprecated use `GetLibraryHubsErrors$inboundSchema` instead. */
  export const inboundSchema = GetLibraryHubsErrors$inboundSchema;
  /** @deprecated use `GetLibraryHubsErrors$outboundSchema` instead. */
  export const outboundSchema = GetLibraryHubsErrors$outboundSchema;
  /** @deprecated use `GetLibraryHubsErrors$Outbound` instead. */
  export type Outbound = GetLibraryHubsErrors$Outbound;
}

export function getLibraryHubsErrorsToJSON(
  getLibraryHubsErrors: GetLibraryHubsErrors,
): string {
  return JSON.stringify(
    GetLibraryHubsErrors$outboundSchema.parse(getLibraryHubsErrors),
  );
}

export function getLibraryHubsErrorsFromJSON(
  jsonString: string,
): SafeParseResult<GetLibraryHubsErrors, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => GetLibraryHubsErrors$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'GetLibraryHubsErrors' from JSON`,
  );
}

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

    return new GetLibraryHubsBadRequest(remapped);
  });

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

/** @internal */
export const GetLibraryHubsBadRequest$outboundSchema: z.ZodType<
  GetLibraryHubsBadRequest$Outbound,
  z.ZodTypeDef,
  GetLibraryHubsBadRequest
> = z.instanceof(GetLibraryHubsBadRequest)
  .transform(v => v.data$)
  .pipe(
    z.object({
      errors: z.array(z.lazy(() => GetLibraryHubsErrors$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 GetLibraryHubsBadRequest$ {
  /** @deprecated use `GetLibraryHubsBadRequest$inboundSchema` instead. */
  export const inboundSchema = GetLibraryHubsBadRequest$inboundSchema;
  /** @deprecated use `GetLibraryHubsBadRequest$outboundSchema` instead. */
  export const outboundSchema = GetLibraryHubsBadRequest$outboundSchema;
  /** @deprecated use `GetLibraryHubsBadRequest$Outbound` instead. */
  export type Outbound = GetLibraryHubsBadRequest$Outbound;
}
