/*
 * 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 GetServerPreferencesServerErrors = {
  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 GetServerPreferencesUnauthorizedData = {
  errors?: Array<GetServerPreferencesServerErrors> | 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 GetServerPreferencesUnauthorized extends Error {
  errors?: Array<GetServerPreferencesServerErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

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

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

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

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

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

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

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

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

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

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

    return new GetServerPreferencesUnauthorized(remapped);
  });

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

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

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

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

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

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

    return new GetServerPreferencesBadRequest(remapped);
  });

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

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