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

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

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

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

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

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

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

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

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

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

export function getBannerImageMediaErrorsToJSON(
  getBannerImageMediaErrors: GetBannerImageMediaErrors,
): string {
  return JSON.stringify(
    GetBannerImageMediaErrors$outboundSchema.parse(getBannerImageMediaErrors),
  );
}

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

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

    return new GetBannerImageUnauthorized(remapped);
  });

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

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

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

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

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

export function getBannerImageErrorsToJSON(
  getBannerImageErrors: GetBannerImageErrors,
): string {
  return JSON.stringify(
    GetBannerImageErrors$outboundSchema.parse(getBannerImageErrors),
  );
}

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

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

    return new GetBannerImageBadRequest(remapped);
  });

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

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