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

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

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

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

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

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

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

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

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

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

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

    return new GetServerResourcesUnauthorized(remapped);
  });

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

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

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

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

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

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

    return new GetServerResourcesBadRequest(remapped);
  });

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

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