/*
 * 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 "../errors/sdkvalidationerror.js";

export type GetThumbImageRequest = {
  /**
   * the id of the library item to return the children of.
   */
  ratingKey: number;
  width: number;
  height: number;
  minSize: number;
  upscale: number;
  /**
   * An authentication token, obtained from plex.tv
   */
  xPlexToken: string;
};

export type GetThumbImageResponse = {
  /**
   * HTTP response content type for this operation
   */
  contentType: string;
  /**
   * HTTP response status code for this operation
   */
  statusCode: number;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse: Response;
  /**
   * Successful response returning an image
   */
  responseStream?: ReadableStream<Uint8Array> | undefined;
  headers: { [k: string]: Array<string> };
};

/** @internal */
export const GetThumbImageRequest$inboundSchema: z.ZodType<
  GetThumbImageRequest,
  z.ZodTypeDef,
  unknown
> = z.object({
  ratingKey: z.number().int(),
  width: z.number().int(),
  height: z.number().int(),
  minSize: z.number().int(),
  upscale: z.number().int(),
  "X-Plex-Token": z.string(),
}).transform((v) => {
  return remap$(v, {
    "X-Plex-Token": "xPlexToken",
  });
});

/** @internal */
export type GetThumbImageRequest$Outbound = {
  ratingKey: number;
  width: number;
  height: number;
  minSize: number;
  upscale: number;
  "X-Plex-Token": string;
};

/** @internal */
export const GetThumbImageRequest$outboundSchema: z.ZodType<
  GetThumbImageRequest$Outbound,
  z.ZodTypeDef,
  GetThumbImageRequest
> = z.object({
  ratingKey: z.number().int(),
  width: z.number().int(),
  height: z.number().int(),
  minSize: z.number().int(),
  upscale: z.number().int(),
  xPlexToken: z.string(),
}).transform((v) => {
  return remap$(v, {
    xPlexToken: "X-Plex-Token",
  });
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace GetThumbImageRequest$ {
  /** @deprecated use `GetThumbImageRequest$inboundSchema` instead. */
  export const inboundSchema = GetThumbImageRequest$inboundSchema;
  /** @deprecated use `GetThumbImageRequest$outboundSchema` instead. */
  export const outboundSchema = GetThumbImageRequest$outboundSchema;
  /** @deprecated use `GetThumbImageRequest$Outbound` instead. */
  export type Outbound = GetThumbImageRequest$Outbound;
}

export function getThumbImageRequestToJSON(
  getThumbImageRequest: GetThumbImageRequest,
): string {
  return JSON.stringify(
    GetThumbImageRequest$outboundSchema.parse(getThumbImageRequest),
  );
}

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

/** @internal */
export const GetThumbImageResponse$inboundSchema: z.ZodType<
  GetThumbImageResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  ContentType: z.string(),
  StatusCode: z.number().int(),
  RawResponse: z.instanceof(Response),
  "response-stream": z.instanceof(ReadableStream<Uint8Array>).optional(),
  Headers: z.record(z.array(z.string())),
}).transform((v) => {
  return remap$(v, {
    "ContentType": "contentType",
    "StatusCode": "statusCode",
    "RawResponse": "rawResponse",
    "response-stream": "responseStream",
    "Headers": "headers",
  });
});

/** @internal */
export type GetThumbImageResponse$Outbound = {
  ContentType: string;
  StatusCode: number;
  RawResponse: never;
  "response-stream"?: ReadableStream<Uint8Array> | undefined;
  Headers: { [k: string]: Array<string> };
};

/** @internal */
export const GetThumbImageResponse$outboundSchema: z.ZodType<
  GetThumbImageResponse$Outbound,
  z.ZodTypeDef,
  GetThumbImageResponse
> = z.object({
  contentType: z.string(),
  statusCode: z.number().int(),
  rawResponse: z.instanceof(Response).transform(() => {
    throw new Error("Response cannot be serialized");
  }),
  responseStream: z.instanceof(ReadableStream<Uint8Array>).optional(),
  headers: z.record(z.array(z.string())),
}).transform((v) => {
  return remap$(v, {
    contentType: "ContentType",
    statusCode: "StatusCode",
    rawResponse: "RawResponse",
    responseStream: "response-stream",
    headers: "Headers",
  });
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace GetThumbImageResponse$ {
  /** @deprecated use `GetThumbImageResponse$inboundSchema` instead. */
  export const inboundSchema = GetThumbImageResponse$inboundSchema;
  /** @deprecated use `GetThumbImageResponse$outboundSchema` instead. */
  export const outboundSchema = GetThumbImageResponse$outboundSchema;
  /** @deprecated use `GetThumbImageResponse$Outbound` instead. */
  export type Outbound = GetThumbImageResponse$Outbound;
}

export function getThumbImageResponseToJSON(
  getThumbImageResponse: GetThumbImageResponse,
): string {
  return JSON.stringify(
    GetThumbImageResponse$outboundSchema.parse(getThumbImageResponse),
  );
}

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