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

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

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

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

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

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

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

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

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

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

export function getBandwidthStatisticsStatisticsErrorsToJSON(
  getBandwidthStatisticsStatisticsErrors:
    GetBandwidthStatisticsStatisticsErrors,
): string {
  return JSON.stringify(
    GetBandwidthStatisticsStatisticsErrors$outboundSchema.parse(
      getBandwidthStatisticsStatisticsErrors,
    ),
  );
}

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

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

    return new GetBandwidthStatisticsUnauthorized(remapped);
  });

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

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

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

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

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

export function getBandwidthStatisticsErrorsToJSON(
  getBandwidthStatisticsErrors: GetBandwidthStatisticsErrors,
): string {
  return JSON.stringify(
    GetBandwidthStatisticsErrors$outboundSchema.parse(
      getBandwidthStatisticsErrors,
    ),
  );
}

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

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

    return new GetBandwidthStatisticsBadRequest(remapped);
  });

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

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