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

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

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

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

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

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

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

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

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

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

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

    return new GetServerListUnauthorized(remapped);
  });

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

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

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

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

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

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

    return new GetServerListBadRequest(remapped);
  });

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

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