/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v3";
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";
import * as shared from "../shared/index.js";

export type TranscodeImageGlobals = {
  /**
   * Indicates the client accepts the indicated media types
   */
  accepts?: shared.Accepts | undefined;
  /**
   * An opaque identifier unique to the client
   */
  clientIdentifier?: string | undefined;
  /**
   * The name of the client product
   */
  product?: string | undefined;
  /**
   * The version of the client application
   */
  version?: string | undefined;
  /**
   * The platform of the client
   */
  platform?: string | undefined;
  /**
   * The version of the platform
   */
  platformVersion?: string | undefined;
  /**
   * A relatively friendly name for the client device
   */
  device?: string | undefined;
  /**
   * A potentially less friendly identifier for the device model
   */
  model?: string | undefined;
  /**
   * The device vendor
   */
  deviceVendor?: string | undefined;
  /**
   * A friendly name for the client
   */
  deviceName?: string | undefined;
  /**
   * The marketplace on which the client application is distributed
   */
  marketplace?: string | undefined;
};

/**
 * The output format for the image; defaults to jpg
 */
export enum Format {
  Jpg = "jpg",
  Jpeg = "jpeg",
  Png = "png",
  Ppm = "ppm",
}

/**
 * Use the specified chroma subsambling.
 *
 * @remarks
 *   - 0: 411
 *   - 1: 420
 *   - 2: 422
 *   - 3: 444
 * Defaults to 3 (444)
 */
export enum ChromaSubsampling {
  Zero = 0,
  One = 1,
  Two = 2,
  Three = 3,
}

export type TranscodeImageRequest = {
  /**
   * Indicates the client accepts the indicated media types
   */
  accepts?: shared.Accepts | undefined;
  /**
   * An opaque identifier unique to the client
   */
  clientIdentifier?: string | undefined;
  /**
   * The name of the client product
   */
  product?: string | undefined;
  /**
   * The version of the client application
   */
  version?: string | undefined;
  /**
   * The platform of the client
   */
  platform?: string | undefined;
  /**
   * The version of the platform
   */
  platformVersion?: string | undefined;
  /**
   * A relatively friendly name for the client device
   */
  device?: string | undefined;
  /**
   * A potentially less friendly identifier for the device model
   */
  model?: string | undefined;
  /**
   * The device vendor
   */
  deviceVendor?: string | undefined;
  /**
   * A friendly name for the client
   */
  deviceName?: string | undefined;
  /**
   * The marketplace on which the client application is distributed
   */
  marketplace?: string | undefined;
  /**
   * The source URL for the image to transcode.  Note, if this URL requires a token such as `X-Plex-Token`, it should be given as a query parameter to this url.
   */
  url?: string | undefined;
  /**
   * The output format for the image; defaults to jpg
   */
  format?: Format | undefined;
  /**
   * The desired width of the output image
   */
  width?: number | undefined;
  /**
   * The desired height of the output image
   */
  height?: number | undefined;
  /**
   * The desired quality of the output.  -1 means the highest quality.  Defaults to -1
   */
  quality?: number | undefined;
  /**
   * The background color to apply before painting the image.  Only really applicable if image has transparency.  Defaults to none
   */
  background?: string | undefined;
  /**
   * Indicates if image should be upscaled to the desired width/height.  Defaults to false
   */
  upscale?: shared.BoolInt | undefined;
  /**
   * Indicates if image should be scaled to fit the smaller dimension.  By default (false) the image is scaled to fit within the width/height specified but if this parameter is true, it will allow overflowing one dimension to fit the other.  Essentially it is making the width/height minimum sizes of the image or sizing the image to fill the entire width/height even if it overflows one dimension.
   */
  minSize?: shared.BoolInt | undefined;
  /**
   * Obey the rotation values specified in EXIF data.  Defaults to true.
   */
  rotate?: shared.BoolInt | undefined;
  /**
   * Apply a blur to the image, Defaults to 0 (none)
   */
  blur?: number | undefined;
  /**
   * Scale the image saturation by the specified percentage.  Defaults to 100
   */
  saturation?: number | undefined;
  /**
   * Render the image at the specified opacity percentage.  Defaults to 100
   */
  opacity?: number | undefined;
  /**
   * Use the specified chroma subsambling.
   *
   * @remarks
   *   - 0: 411
   *   - 1: 420
   *   - 2: 422
   *   - 3: 444
   * Defaults to 3 (444)
   */
  chromaSubsampling?: ChromaSubsampling | undefined;
  /**
   * The color to blend with the image.  Defaults to none
   */
  blendColor?: string | undefined;
};

export type TranscodeImageResponse = {
  /**
   * 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;
  /**
   * The resulting image
   */
  twoHundredImageJpegResponseStream?: ReadableStream<Uint8Array> | undefined;
  /**
   * The resulting image
   */
  twoHundredImagePngResponseStream?: ReadableStream<Uint8Array> | undefined;
  /**
   * The resulting image
   */
  twoHundredImageXPortablePixmapResponseStream?:
    | ReadableStream<Uint8Array>
    | undefined;
};

/** @internal */
export const Format$outboundSchema: z.ZodNativeEnum<typeof Format> = z
  .nativeEnum(Format);

/** @internal */
export const ChromaSubsampling$outboundSchema: z.ZodNativeEnum<
  typeof ChromaSubsampling
> = z.nativeEnum(ChromaSubsampling);

/** @internal */
export type TranscodeImageRequest$Outbound = {
  accepts: string;
  "Client-Identifier"?: string | undefined;
  Product?: string | undefined;
  Version?: string | undefined;
  Platform?: string | undefined;
  "Platform-Version"?: string | undefined;
  Device?: string | undefined;
  Model?: string | undefined;
  "Device-Vendor"?: string | undefined;
  "Device-Name"?: string | undefined;
  Marketplace?: string | undefined;
  url?: string | undefined;
  format?: string | undefined;
  width?: number | undefined;
  height?: number | undefined;
  quality?: number | undefined;
  background?: string | undefined;
  upscale: number;
  minSize: number;
  rotate: number;
  blur?: number | undefined;
  saturation?: number | undefined;
  opacity?: number | undefined;
  chromaSubsampling?: number | undefined;
  blendColor?: string | undefined;
};

/** @internal */
export const TranscodeImageRequest$outboundSchema: z.ZodType<
  TranscodeImageRequest$Outbound,
  z.ZodTypeDef,
  TranscodeImageRequest
> = z.object({
  accepts: shared.Accepts$outboundSchema.default(shared.Accepts.ApplicationXml),
  clientIdentifier: z.string().optional(),
  product: z.string().optional(),
  version: z.string().optional(),
  platform: z.string().optional(),
  platformVersion: z.string().optional(),
  device: z.string().optional(),
  model: z.string().optional(),
  deviceVendor: z.string().optional(),
  deviceName: z.string().optional(),
  marketplace: z.string().optional(),
  url: z.string().optional(),
  format: Format$outboundSchema.optional(),
  width: z.number().int().optional(),
  height: z.number().int().optional(),
  quality: z.number().int().optional(),
  background: z.string().optional(),
  upscale: shared.BoolInt$outboundSchema.default(shared.BoolInt.False),
  minSize: shared.BoolInt$outboundSchema.default(shared.BoolInt.False),
  rotate: shared.BoolInt$outboundSchema.default(shared.BoolInt.False),
  blur: z.number().int().optional(),
  saturation: z.number().int().optional(),
  opacity: z.number().int().optional(),
  chromaSubsampling: ChromaSubsampling$outboundSchema.optional(),
  blendColor: z.string().optional(),
}).transform((v) => {
  return remap$(v, {
    clientIdentifier: "Client-Identifier",
    product: "Product",
    version: "Version",
    platform: "Platform",
    platformVersion: "Platform-Version",
    device: "Device",
    model: "Model",
    deviceVendor: "Device-Vendor",
    deviceName: "Device-Name",
    marketplace: "Marketplace",
  });
});

export function transcodeImageRequestToJSON(
  transcodeImageRequest: TranscodeImageRequest,
): string {
  return JSON.stringify(
    TranscodeImageRequest$outboundSchema.parse(transcodeImageRequest),
  );
}

/** @internal */
export const TranscodeImageResponse$inboundSchema: z.ZodType<
  TranscodeImageResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  ContentType: z.string(),
  StatusCode: z.number().int(),
  RawResponse: z.instanceof(Response),
  "200_image/jpeg_response-stream": z.instanceof(ReadableStream<Uint8Array>)
    .optional(),
  "200_image/png_response-stream": z.instanceof(ReadableStream<Uint8Array>)
    .optional(),
  "200_image/x-portable-pixmap_response-stream": z.instanceof(
    ReadableStream<Uint8Array>,
  ).optional(),
}).transform((v) => {
  return remap$(v, {
    "ContentType": "contentType",
    "StatusCode": "statusCode",
    "RawResponse": "rawResponse",
    "200_image/jpeg_response-stream": "twoHundredImageJpegResponseStream",
    "200_image/png_response-stream": "twoHundredImagePngResponseStream",
    "200_image/x-portable-pixmap_response-stream":
      "twoHundredImageXPortablePixmapResponseStream",
  });
});

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