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

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

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

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

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

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

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

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

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

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

export function getHomeDataPlexErrorsToJSON(
  getHomeDataPlexErrors: GetHomeDataPlexErrors,
): string {
  return JSON.stringify(
    GetHomeDataPlexErrors$outboundSchema.parse(getHomeDataPlexErrors),
  );
}

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

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

    return new GetHomeDataUnauthorized(remapped);
  });

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

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

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

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

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

export function getHomeDataErrorsToJSON(
  getHomeDataErrors: GetHomeDataErrors,
): string {
  return JSON.stringify(
    GetHomeDataErrors$outboundSchema.parse(getHomeDataErrors),
  );
}

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

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

    return new GetHomeDataBadRequest(remapped);
  });

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

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