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

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

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

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

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

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

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

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

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

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

export function getThumbImageMediaErrorsToJSON(
  getThumbImageMediaErrors: GetThumbImageMediaErrors,
): string {
  return JSON.stringify(
    GetThumbImageMediaErrors$outboundSchema.parse(getThumbImageMediaErrors),
  );
}

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

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

    return new GetThumbImageUnauthorized(remapped);
  });

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

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

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

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

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

export function getThumbImageErrorsToJSON(
  getThumbImageErrors: GetThumbImageErrors,
): string {
  return JSON.stringify(
    GetThumbImageErrors$outboundSchema.parse(getThumbImageErrors),
  );
}

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

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

    return new GetThumbImageBadRequest(remapped);
  });

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

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