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

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

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

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

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

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

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

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

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

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

export function getResourcesStatisticsStatisticsErrorsToJSON(
  getResourcesStatisticsStatisticsErrors:
    GetResourcesStatisticsStatisticsErrors,
): string {
  return JSON.stringify(
    GetResourcesStatisticsStatisticsErrors$outboundSchema.parse(
      getResourcesStatisticsStatisticsErrors,
    ),
  );
}

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

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

    return new GetResourcesStatisticsUnauthorized(remapped);
  });

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

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

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

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

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

export function getResourcesStatisticsErrorsToJSON(
  getResourcesStatisticsErrors: GetResourcesStatisticsErrors,
): string {
  return JSON.stringify(
    GetResourcesStatisticsErrors$outboundSchema.parse(
      getResourcesStatisticsErrors,
    ),
  );
}

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

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

    return new GetResourcesStatisticsBadRequest(remapped);
  });

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

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