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

export type AddDownloadQueueItemsRequest = {
  /**
   * 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 queue id
   */
  queueId: number;
  /**
   * Keys to add
   */
  keys: Array<string>;
  /**
   * 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?: shared.LocationParameter | 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?: shared.ProtocolParameter | 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?: shared.Subtitles | undefined;
  /**
   * Target video bitrate (in kbps).
   */
  videoBitrate?: number | undefined;
  /**
   * Target photo quality.
   */
  videoQuality?: number | undefined;
  /**
   * Target maximum video resolution.
   */
  videoResolution?: string | undefined;
};

export type AddedQueueItem = {
  /**
   * The queue item id that was added or the existing one if an item already exists in this queue with the same parameters
   */
  id?: number | undefined;
  /**
   * The key added to the queue
   */
  key?: string | undefined;
};

/**
 * `MediaContainer` is the root element of most Plex API responses. It serves as a generic container for various types of content (Metadata, Hubs, Directories, etc.) and includes pagination information (offset, size, totalSize) when applicable.
 *
 * @remarks
 * Common attributes: - identifier: Unique identifier for this container - size: Number of items in this response page - totalSize: Total number of items available (for pagination) - offset: Starting index of this page (for pagination)
 * The container often "hoists" common attributes from its children. For example, if all tracks in a container share the same album title, the `parentTitle` attribute may appear on the MediaContainer rather than being repeated on each track.
 */
export type AddDownloadQueueItemsMediaContainer = {
  identifier?: string | undefined;
  /**
   * The offset of where this container page starts among the total objects available. Also provided in the `X-Plex-Container-Start` header.
   *
   * @remarks
   */
  offset?: number | undefined;
  size?: number | undefined;
  /**
   * The total size of objects available. Also provided in the `X-Plex-Container-Total-Size` header.
   *
   * @remarks
   */
  totalSize?: number | undefined;
  addedQueueItems?: Array<AddedQueueItem> | undefined;
};

/**
 * OK
 */
export type AddDownloadQueueItemsResponseBody = {
  mediaContainer?: AddDownloadQueueItemsMediaContainer | undefined;
};

export type AddDownloadQueueItemsResponse = {
  /**
   * 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;
  /**
   * OK
   */
  object?: AddDownloadQueueItemsResponseBody | undefined;
};

/** @internal */
export type AddDownloadQueueItemsRequest$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;
  queueId: number;
  keys: Array<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;
};

/** @internal */
export const AddDownloadQueueItemsRequest$outboundSchema: z.ZodType<
  AddDownloadQueueItemsRequest$Outbound,
  z.ZodTypeDef,
  AddDownloadQueueItemsRequest
> = 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(),
  queueId: z.number().int(),
  keys: z.array(z.string()),
  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: shared.LocationParameter$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: shared.ProtocolParameter$outboundSchema.optional(),
  secondsPerSegment: z.number().int().optional(),
  subtitleSize: z.number().int().optional(),
  subtitles: shared.Subtitles$outboundSchema.optional(),
  videoBitrate: z.number().int().optional(),
  videoQuality: z.number().int().optional(),
  videoResolution: 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 addDownloadQueueItemsRequestToJSON(
  addDownloadQueueItemsRequest: AddDownloadQueueItemsRequest,
): string {
  return JSON.stringify(
    AddDownloadQueueItemsRequest$outboundSchema.parse(
      addDownloadQueueItemsRequest,
    ),
  );
}

/** @internal */
export const AddedQueueItem$inboundSchema: z.ZodType<
  AddedQueueItem,
  z.ZodTypeDef,
  unknown
> = z.object({
  id: z.number().int().optional(),
  key: z.string().optional(),
});

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

/** @internal */
export const AddDownloadQueueItemsMediaContainer$inboundSchema: z.ZodType<
  AddDownloadQueueItemsMediaContainer,
  z.ZodTypeDef,
  unknown
> = z.object({
  identifier: z.string().optional(),
  offset: z.number().int().optional(),
  size: z.number().int().optional(),
  totalSize: z.number().int().optional(),
  AddedQueueItems: z.array(z.lazy(() => AddedQueueItem$inboundSchema))
    .optional(),
}).transform((v) => {
  return remap$(v, {
    "AddedQueueItems": "addedQueueItems",
  });
});

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

/** @internal */
export const AddDownloadQueueItemsResponseBody$inboundSchema: z.ZodType<
  AddDownloadQueueItemsResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  MediaContainer: z.lazy(() =>
    AddDownloadQueueItemsMediaContainer$inboundSchema
  ).optional(),
}).transform((v) => {
  return remap$(v, {
    "MediaContainer": "mediaContainer",
  });
});

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

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

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