/*
 * 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 StartTranscodeSessionGlobals = {
  /**
   * 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;
};

/**
 * Extension
 *
 * @remarks
 */
export enum Extension {
  M3u8 = "m3u8",
  Mpd = "mpd",
}

/**
 * Network type of the client, can be used to help determine target bitrate.
 */
export enum StartTranscodeSessionLocation {
  Lan = "lan",
  Wan = "wan",
  Cellular = "cellular",
}

/**
 * Indicates the network streaming protocol to be used for the transcode session: * 'http' - include the file in the http response such as MKV streaming * 'hls' - hls stream (RFC 8216) * 'dash' - dash stream (ISO/IEC 23009-1:2022)
 *
 * @remarks
 */
export enum StartTranscodeSessionProtocol {
  Http = "http",
  Hls = "hls",
  Dash = "dash",
}

/**
 * Indicates how subtitles should be included: * 'auto' - Compute the appropriate subtitle setting automatically * 'burn' - Burn the selected subtitle; auto if no selected subtitle * 'none' - Ignore all subtitle streams * 'sidecar' - The selected subtitle should be provided as a sidecar * 'embedded' - The selected subtitle should be provided as an embedded stream * 'segmented' - The selected subtitle should be provided as a segmented stream
 *
 * @remarks
 */
export enum StartTranscodeSessionSubtitles {
  Auto = "auto",
  Burn = "burn",
  None = "none",
  Sidecar = "sidecar",
  Embedded = "embedded",
  Segmented = "segmented",
  Unknown = "unknown",
}

export type StartTranscodeSessionRequest = {
  /**
   * 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;
  /**
   * Type of transcode media
   */
  transcodeType: shared.TranscodeType;
  /**
   * Transcode session UUID
   */
  transcodeSessionId?: string | undefined;
  /**
   * Extension
   *
   * @remarks
   */
  extension: Extension;
  /**
   * Indicates how incompatible advanced subtitles (such as ass/ssa) should be included: * 'burn' - Burn incompatible advanced text subtitles into the video stream * 'text' - Transcode incompatible advanced text subtitles to a compatible text format, even if some markup is lost
   *
   * @remarks
   */
  advancedSubtitles?: shared.AdvancedSubtitles | undefined;
  /**
   * Percentage of original audio loudness to use when transcoding (100 is equivalent to original volume, 50 is half, 200 is double, etc)
   */
  audioBoost?: number | undefined;
  /**
   * Target video number of audio channels.
   */
  audioChannelCount?: number | undefined;
  /**
   * Indicates the client supports ABR.
   */
  autoAdjustQuality?: shared.BoolInt | undefined;
  /**
   * Indicates if the server should adjust subtitles based on Voice Activity Data.
   */
  autoAdjustSubtitle?: shared.BoolInt | undefined;
  /**
   * Indicates the client supports direct playing the indicated content.
   */
  directPlay?: shared.BoolInt | undefined;
  /**
   * Indicates the client supports direct streaming the video of the indicated content.
   */
  directStream?: shared.BoolInt | undefined;
  /**
   * Indicates the client supports direct streaming the audio of the indicated content.
   */
  directStreamAudio?: shared.BoolInt | undefined;
  /**
   * Indicates if resolution should be adjusted for orientation.
   */
  disableResolutionRotation?: shared.BoolInt | undefined;
  /**
   * Ignore client profiles when determining if direct play is possible. Only has an effect when directPlay=1 and both mediaIndex and partIndex are specified and neither are -1
   */
  hasMDE?: shared.BoolInt | undefined;
  /**
   * Network type of the client, can be used to help determine target bitrate.
   */
  location?: StartTranscodeSessionLocation | undefined;
  /**
   * Buffer size used in playback (in KB). Clients should specify a lower bound if not known exactly. This value could make the difference between transcoding and direct play on bandwidth constrained networks.
   */
  mediaBufferSize?: number | undefined;
  /**
   * Index of the media to transcode. -1 or not specified indicates let the server choose.
   */
  mediaIndex?: number | undefined;
  /**
   * Target bitrate for audio only files (in kbps, used to transcode).
   */
  musicBitrate?: number | undefined;
  /**
   * Offset from the start of the media (in seconds).
   */
  offset?: number | undefined;
  /**
   * Index of the part to transcode. -1 or not specified indicates the server should join parts together in a transcode
   */
  partIndex?: number | undefined;
  /**
   * Internal PMS path of the media to transcode.
   */
  path?: string | undefined;
  /**
   * Maximum bitrate (in kbps) to use in ABR.
   */
  peakBitrate?: number | undefined;
  /**
   * Target photo resolution.
   */
  photoResolution?: string | undefined;
  /**
   * Indicates the network streaming protocol to be used for the transcode session: * 'http' - include the file in the http response such as MKV streaming * 'hls' - hls stream (RFC 8216) * 'dash' - dash stream (ISO/IEC 23009-1:2022)
   *
   * @remarks
   */
  protocol?: StartTranscodeSessionProtocol | undefined;
  /**
   * Number of seconds to include in each transcoded segment
   */
  secondsPerSegment?: number | undefined;
  /**
   * Percentage of original subtitle size to use when burning subtitles (100 is equivalent to original size, 50 is half, ect)
   */
  subtitleSize?: number | undefined;
  /**
   * Indicates how subtitles should be included: * 'auto' - Compute the appropriate subtitle setting automatically * 'burn' - Burn the selected subtitle; auto if no selected subtitle * 'none' - Ignore all subtitle streams * 'sidecar' - The selected subtitle should be provided as a sidecar * 'embedded' - The selected subtitle should be provided as an embedded stream * 'segmented' - The selected subtitle should be provided as a segmented stream
   *
   * @remarks
   */
  subtitles?: StartTranscodeSessionSubtitles | undefined;
  /**
   * Target video bitrate (in kbps).
   */
  videoBitrate?: number | undefined;
  /**
   * Target photo quality.
   */
  videoQuality?: number | undefined;
  /**
   * Target maximum video resolution.
   */
  videoResolution?: string | undefined;
  /**
   * See [Profile Augmentations](#section/API-Info/Profile-Augmentations) .
   */
  xPlexClientProfileExtra?: string | undefined;
  /**
   * Which built in Client Profile to use in the decision. Generally should only be used to specify the Generic profile.
   */
  xPlexClientProfileName?: string | undefined;
  /**
   * Unique per client playback session.  Used if a client can playback multiple items at a time (such as a browser with multiple tabs)
   */
  xPlexSessionIdentifier?: string | undefined;
};

export type StartTranscodeSessionResponse = {
  /**
   * 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;
  /**
   * MPD file (see ISO/IEC 23009-1:2022), m3u8 file (see RFC 8216), or binary http stream
   */
  responseStream?: ReadableStream<Uint8Array> | undefined;
};

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

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

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

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

/** @internal */
export type StartTranscodeSessionRequest$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;
  transcodeType: string;
  transcodeSessionId?: string | undefined;
  extension: string;
  advancedSubtitles?: string | undefined;
  audioBoost?: number | undefined;
  audioChannelCount?: number | undefined;
  autoAdjustQuality: number;
  autoAdjustSubtitle: number;
  directPlay: number;
  directStream: number;
  directStreamAudio: number;
  disableResolutionRotation: number;
  hasMDE: number;
  location?: string | undefined;
  mediaBufferSize?: number | undefined;
  mediaIndex?: number | undefined;
  musicBitrate?: number | undefined;
  offset?: number | undefined;
  partIndex?: number | undefined;
  path?: string | undefined;
  peakBitrate?: number | undefined;
  photoResolution?: string | undefined;
  protocol?: string | undefined;
  secondsPerSegment?: number | undefined;
  subtitleSize?: number | undefined;
  subtitles?: string | undefined;
  videoBitrate?: number | undefined;
  videoQuality?: number | undefined;
  videoResolution?: string | undefined;
  "X-Plex-Client-Profile-Extra"?: string | undefined;
  "X-Plex-Client-Profile-Name"?: string | undefined;
  "X-Plex-Session-Identifier"?: string | undefined;
};

/** @internal */
export const StartTranscodeSessionRequest$outboundSchema: z.ZodType<
  StartTranscodeSessionRequest$Outbound,
  z.ZodTypeDef,
  StartTranscodeSessionRequest
> = 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(),
  transcodeType: shared.TranscodeType$outboundSchema,
  transcodeSessionId: z.string().optional(),
  extension: Extension$outboundSchema,
  advancedSubtitles: shared.AdvancedSubtitles$outboundSchema.optional(),
  audioBoost: z.number().int().optional(),
  audioChannelCount: z.number().int().optional(),
  autoAdjustQuality: shared.BoolInt$outboundSchema.default(
    shared.BoolInt.False,
  ),
  autoAdjustSubtitle: shared.BoolInt$outboundSchema.default(
    shared.BoolInt.False,
  ),
  directPlay: shared.BoolInt$outboundSchema.default(shared.BoolInt.False),
  directStream: shared.BoolInt$outboundSchema.default(shared.BoolInt.False),
  directStreamAudio: shared.BoolInt$outboundSchema.default(
    shared.BoolInt.False,
  ),
  disableResolutionRotation: shared.BoolInt$outboundSchema.default(
    shared.BoolInt.False,
  ),
  hasMDE: shared.BoolInt$outboundSchema.default(shared.BoolInt.False),
  location: StartTranscodeSessionLocation$outboundSchema.optional(),
  mediaBufferSize: z.number().int().optional(),
  mediaIndex: z.number().int().optional(),
  musicBitrate: z.number().int().optional(),
  offset: z.number().optional(),
  partIndex: z.number().int().optional(),
  path: z.string().optional(),
  peakBitrate: z.number().int().optional(),
  photoResolution: z.string().optional(),
  protocol: StartTranscodeSessionProtocol$outboundSchema.optional(),
  secondsPerSegment: z.number().int().optional(),
  subtitleSize: z.number().int().optional(),
  subtitles: StartTranscodeSessionSubtitles$outboundSchema.optional(),
  videoBitrate: z.number().int().optional(),
  videoQuality: z.number().int().optional(),
  videoResolution: z.string().optional(),
  xPlexClientProfileExtra: z.string().optional(),
  xPlexClientProfileName: z.string().optional(),
  xPlexSessionIdentifier: 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",
    xPlexClientProfileExtra: "X-Plex-Client-Profile-Extra",
    xPlexClientProfileName: "X-Plex-Client-Profile-Name",
    xPlexSessionIdentifier: "X-Plex-Session-Identifier",
  });
});

export function startTranscodeSessionRequestToJSON(
  startTranscodeSessionRequest: StartTranscodeSessionRequest,
): string {
  return JSON.stringify(
    StartTranscodeSessionRequest$outboundSchema.parse(
      startTranscodeSessionRequest,
    ),
  );
}

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

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