/*
 * 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 {
  collectExtraKeys as collectExtraKeys$,
  safeParse,
} from "../../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

/**
 * `Stream` represents a particular stream from a media item, such as the video stream, audio stream, or subtitle stream. The stream may either be part of the file represented by the parent `Part` or, especially for subtitles, an external file. The stream contains more detailed information about the specific stream. For example, a video may include the `aspectRatio` at the `Media` level, but detailed information about the video stream like the color space will be included on the `Stream` for the video stream.  Note that photos do not have streams (mostly as an optimization).
 *
 * @remarks
 */
export type Stream = {
  /**
   * Indicates if this stream is default.
   */
  default?: boolean | undefined;
  /**
   * Audio channel layout.
   */
  audioChannelLayout?: string | undefined;
  /**
   * Number of audio channels (for audio streams).
   */
  channels?: number | undefined;
  /**
   * Bit depth of the video stream.
   */
  bitDepth?: number | undefined;
  /**
   * Dolby Vision BL compatibility ID.
   */
  doviblCompatID?: number | undefined;
  /**
   * Indicates if Dolby Vision BL is present.
   */
  doviblPresent?: boolean | undefined;
  /**
   * Indicates if Dolby Vision EL is present.
   */
  dovielPresent?: boolean | undefined;
  /**
   * Dolby Vision level.
   */
  doviLevel?: number | undefined;
  /**
   * Indicates if Dolby Vision is present.
   */
  doviPresent?: boolean | undefined;
  /**
   * Dolby Vision profile.
   */
  doviProfile?: number | undefined;
  /**
   * Indicates if Dolby Vision RPU is present.
   */
  dovirpuPresent?: boolean | undefined;
  /**
   * Dolby Vision version.
   */
  doviVersion?: string | undefined;
  /**
   * Bitrate of the stream.
   */
  bitrate?: number | undefined;
  /**
   * Indicates if the stream can auto-sync.
   */
  canAutoSync?: boolean | undefined;
  /**
   * Chroma sample location.
   */
  chromaLocation?: string | undefined;
  /**
   * Chroma subsampling format.
   */
  chromaSubsampling?: string | undefined;
  /**
   * Coded video height.
   */
  codedHeight?: number | undefined;
  /**
   * Coded video width.
   */
  codedWidth?: number | undefined;
  closedCaptions?: boolean | undefined;
  /**
   * Codec used by the stream.
   */
  codec: string;
  /**
   * Color primaries used.
   */
  colorPrimaries?: string | undefined;
  /**
   * Color range (e.g., tv).
   */
  colorRange?: string | undefined;
  /**
   * Color space.
   */
  colorSpace?: string | undefined;
  /**
   * Color transfer characteristics.
   */
  colorTrc?: string | undefined;
  /**
   * Display title for the stream.
   */
  displayTitle: string;
  /**
   * Extended display title for the stream.
   */
  extendedDisplayTitle?: string | undefined;
  /**
   * Frame rate of the stream.
   */
  frameRate?: number | undefined;
  hasScalingMatrix?: boolean | undefined;
  /**
   * Height of the video stream.
   */
  height?: number | undefined;
  /**
   * Unique stream identifier.
   */
  id: number;
  /**
   * Index of the stream.
   */
  index?: number | undefined;
  /**
   * Key to access this stream part.
   */
  key: string;
  /**
   * Language of the stream.
   */
  language?: string | undefined;
  /**
   * ISO language code.
   */
  languageCode?: string | undefined;
  /**
   * Language tag (e.g., en).
   */
  languageTag?: string | undefined;
  /**
   * Format of the stream (e.g., srt).
   */
  format?: string | undefined;
  /**
   * Indicates whether header compression is enabled.
   */
  headerCompression?: boolean | undefined;
  /**
   * Video level.
   */
  level?: number | undefined;
  /**
   * Indicates if this is the original stream.
   */
  original?: boolean | undefined;
  /**
   * Video profile.
   */
  profile?: string | undefined;
  /**
   * Number of reference frames.
   */
  refFrames?: number | undefined;
  /**
   * Sampling rate for the audio stream.
   */
  samplingRate?: number | undefined;
  scanType?: string | undefined;
  embeddedInVideo?: string | undefined;
  /**
   * Indicates if this stream is selected (applicable for audio streams).
   */
  selected?: boolean | undefined;
  forced?: boolean | undefined;
  /**
   * Indicates if the stream is for the hearing impaired.
   */
  hearingImpaired?: boolean | undefined;
  /**
   * Indicates if the stream is a dub.
   */
  dub?: boolean | undefined;
  /**
   * Optional title for the stream (e.g., language variant).
   */
  title?: string | undefined;
  streamIdentifier?: number | undefined;
  /**
   * Stream type:
   *
   * @remarks
   *   - VIDEO = 1
   *   - AUDIO = 2
   *   - SUBTITLE = 3
   */
  streamType?: 1 | undefined;
  /**
   * Width of the video stream.
   */
  width?: number | undefined;
  additionalProperties?: { [k: string]: any } | undefined;
};

/** @internal */
export const Stream$inboundSchema: z.ZodType<Stream, z.ZodTypeDef, unknown> =
  collectExtraKeys$(
    z.object({
      default: z.boolean().optional(),
      audioChannelLayout: z.string().optional(),
      channels: z.number().int().optional(),
      bitDepth: z.number().int().optional(),
      DOVIBLCompatID: z.number().int().optional(),
      DOVIBLPresent: z.boolean().optional(),
      DOVIELPresent: z.boolean().optional(),
      DOVILevel: z.number().int().optional(),
      DOVIPresent: z.boolean().optional(),
      DOVIProfile: z.number().int().optional(),
      DOVIRPUPresent: z.boolean().optional(),
      DOVIVersion: z.string().optional(),
      bitrate: z.number().int().optional(),
      canAutoSync: z.boolean().optional(),
      chromaLocation: z.string().optional(),
      chromaSubsampling: z.string().optional(),
      codedHeight: z.number().int().optional(),
      codedWidth: z.number().int().optional(),
      closedCaptions: z.boolean().optional(),
      codec: z.string(),
      colorPrimaries: z.string().optional(),
      colorRange: z.string().optional(),
      colorSpace: z.string().optional(),
      colorTrc: z.string().optional(),
      displayTitle: z.string(),
      extendedDisplayTitle: z.string().optional(),
      frameRate: z.number().optional(),
      hasScalingMatrix: z.boolean().optional(),
      height: z.number().int().optional(),
      id: z.number().int(),
      index: z.number().int().optional(),
      key: z.string(),
      language: z.string().optional(),
      languageCode: z.string().optional(),
      languageTag: z.string().optional(),
      format: z.string().optional(),
      headerCompression: z.boolean().optional(),
      level: z.number().int().optional(),
      original: z.boolean().optional(),
      profile: z.string().optional(),
      refFrames: z.number().int().optional(),
      samplingRate: z.number().int().optional(),
      scanType: z.string().optional(),
      embeddedInVideo: z.string().optional(),
      selected: z.boolean().optional(),
      forced: z.boolean().optional(),
      hearingImpaired: z.boolean().optional(),
      dub: z.boolean().optional(),
      title: z.string().optional(),
      streamIdentifier: z.number().int().optional(),
      streamType: z.literal(1).default(1).optional(),
      width: z.number().int().optional(),
    }).catchall(z.any()),
    "additionalProperties",
    true,
  ).transform((v) => {
    return remap$(v, {
      "DOVIBLCompatID": "doviblCompatID",
      "DOVIBLPresent": "doviblPresent",
      "DOVIELPresent": "dovielPresent",
      "DOVILevel": "doviLevel",
      "DOVIPresent": "doviPresent",
      "DOVIProfile": "doviProfile",
      "DOVIRPUPresent": "dovirpuPresent",
      "DOVIVersion": "doviVersion",
    });
  });

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