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

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

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

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

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

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

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

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

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

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

export function getUpdateStatusUpdaterErrorsToJSON(
  getUpdateStatusUpdaterErrors: GetUpdateStatusUpdaterErrors,
): string {
  return JSON.stringify(
    GetUpdateStatusUpdaterErrors$outboundSchema.parse(
      getUpdateStatusUpdaterErrors,
    ),
  );
}

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

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

    return new GetUpdateStatusUnauthorized(remapped);
  });

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

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

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

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

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

export function getUpdateStatusErrorsToJSON(
  getUpdateStatusErrors: GetUpdateStatusErrors,
): string {
  return JSON.stringify(
    GetUpdateStatusErrors$outboundSchema.parse(getUpdateStatusErrors),
  );
}

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

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

    return new GetUpdateStatusBadRequest(remapped);
  });

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

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