/*
 * 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";
import { Part, Part$inboundSchema } from "./part.js";

/**
 * `Media` represents an one or more media files (parts) and is a child of a metadata item. There aren't necessarily any guaranteed attributes on media elements since the attributes will vary based on the type. The possible attributes are not documented here, but they typically have self-evident names. High-level media information that can be used for badging and flagging, such as `videoResolution` and codecs, is included on the media element.
 *
 * @remarks
 */
export type Media = {
  aspectRatio?: number | undefined;
  audioChannels?: number | undefined;
  audioCodec?: string | undefined;
  audioProfile?: string | undefined;
  bitrate?: number | undefined;
  container?: string | undefined;
  duration?: number | undefined;
  has64bitOffsets?: boolean | undefined;
  hasVoiceActivity?: boolean | undefined;
  height?: number | undefined;
  id: number;
  optimizedForStreaming?: boolean | undefined;
  part?: Array<Part> | undefined;
  videoCodec?: string | undefined;
  videoFrameRate?: string | undefined;
  videoProfile?: string | undefined;
  videoResolution?: string | undefined;
  width?: number | undefined;
  additionalProperties?: { [k: string]: any } | undefined;
};

/** @internal */
export const Media$inboundSchema: z.ZodType<Media, z.ZodTypeDef, unknown> =
  collectExtraKeys$(
    z.object({
      aspectRatio: z.number().optional(),
      audioChannels: z.number().int().optional(),
      audioCodec: z.string().optional(),
      audioProfile: z.string().optional(),
      bitrate: z.number().int().optional(),
      container: z.string().optional(),
      duration: z.number().int().optional(),
      has64bitOffsets: z.boolean().optional(),
      hasVoiceActivity: z.boolean().optional(),
      height: z.number().int().optional(),
      id: z.number().int(),
      optimizedForStreaming: z.boolean().optional(),
      Part: z.array(Part$inboundSchema).optional(),
      videoCodec: z.string().optional(),
      videoFrameRate: z.string().optional(),
      videoProfile: z.string().optional(),
      videoResolution: z.string().optional(),
      width: z.number().int().optional(),
    }).catchall(z.any()),
    "additionalProperties",
    true,
  ).transform((v) => {
    return remap$(v, {
      "Part": "part",
    });
  });

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