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

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

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

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

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

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

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

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

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

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

export function getStatisticsStatisticsErrorsToJSON(
  getStatisticsStatisticsErrors: GetStatisticsStatisticsErrors,
): string {
  return JSON.stringify(
    GetStatisticsStatisticsErrors$outboundSchema.parse(
      getStatisticsStatisticsErrors,
    ),
  );
}

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

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

    return new GetStatisticsUnauthorized(remapped);
  });

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

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

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

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

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

export function getStatisticsErrorsToJSON(
  getStatisticsErrors: GetStatisticsErrors,
): string {
  return JSON.stringify(
    GetStatisticsErrors$outboundSchema.parse(getStatisticsErrors),
  );
}

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

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

    return new GetStatisticsBadRequest(remapped);
  });

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

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