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

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

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

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

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

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

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

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

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

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

export function checkForUpdatesUpdaterErrorsToJSON(
  checkForUpdatesUpdaterErrors: CheckForUpdatesUpdaterErrors,
): string {
  return JSON.stringify(
    CheckForUpdatesUpdaterErrors$outboundSchema.parse(
      checkForUpdatesUpdaterErrors,
    ),
  );
}

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

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

    return new CheckForUpdatesUnauthorized(remapped);
  });

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

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

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

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

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

export function checkForUpdatesErrorsToJSON(
  checkForUpdatesErrors: CheckForUpdatesErrors,
): string {
  return JSON.stringify(
    CheckForUpdatesErrors$outboundSchema.parse(checkForUpdatesErrors),
  );
}

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

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

    return new CheckForUpdatesBadRequest(remapped);
  });

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

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