/*
 * 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 GetDownloadQueueItemsGlobals = {
  /**
   * 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 GetDownloadQueueItemsRequest = {
  /**
   * 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;
  /**
   * The item ids
   */
  itemId: Array<number>;
};

export type GetDownloadQueueItemsDecisionResult = {
  /**
   * The maximum bitrate set when item was added
   */
  availableBandwidth?: number | undefined;
  directPlayDecisionCode?: number | undefined;
  directPlayDecisionText?: string | undefined;
  generalDecisionCode?: number | undefined;
  generalDecisionText?: string | undefined;
  /**
   * The code indicating the status of evaluation of playback when client indicates `hasMDE=1`
   */
  mdeDecisionCode?: number | undefined;
  /**
   * Descriptive text for the above code
   */
  mdeDecisionText?: string | undefined;
  transcodeDecisionCode?: number | undefined;
  transcodeDecisionText?: string | undefined;
};

/**
 * The state of the item:
 *
 * @remarks
 *   - deciding: The item decision is pending
 *   - waiting: The item is waiting for transcode
 *   - processing: The item is being transcoded
 *   - available: The item is available for download
 *   - error: The item encountered an error in the decision or transcode
 *   - expired: The transcoded item has timed out and is no longer available
 */
export enum GetDownloadQueueItemsStatus {
  Deciding = "deciding",
  Waiting = "waiting",
  Processing = "processing",
  Available = "available",
  Error = "error",
  Expired = "expired",
}

/**
 * The transcode session object which is not yet documented otherwise it'd be a $ref here.
 */
export type GetDownloadQueueItemsTranscode = {};

export type GetDownloadQueueItemsDownloadQueueItem = {
  decisionResult?: GetDownloadQueueItemsDecisionResult | undefined;
  /**
   * The error encountered in transcoding or decision
   */
  error?: string | undefined;
  id?: number | undefined;
  key?: string | undefined;
  queueId?: number | undefined;
  /**
   * The state of the item:
   *
   * @remarks
   *   - deciding: The item decision is pending
   *   - waiting: The item is waiting for transcode
   *   - processing: The item is being transcoded
   *   - available: The item is available for download
   *   - error: The item encountered an error in the decision or transcode
   *   - expired: The transcoded item has timed out and is no longer available
   */
  status?: GetDownloadQueueItemsStatus | undefined;
  /**
   * The transcode session object which is not yet documented otherwise it'd be a $ref here.
   */
  transcode?: GetDownloadQueueItemsTranscode | undefined;
  /**
   * The transcode session if item is currently being transcoded
   */
  transcodeSession?: shared.TranscodeSession | 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 GetDownloadQueueItemsMediaContainer = {
  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;
  downloadQueueItem?: Array<GetDownloadQueueItemsDownloadQueueItem> | undefined;
};

/**
 * OK
 */
export type GetDownloadQueueItemsResponseBody = {
  mediaContainer?: GetDownloadQueueItemsMediaContainer | undefined;
};

export type GetDownloadQueueItemsResponse = {
  /**
   * 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?: GetDownloadQueueItemsResponseBody | undefined;
};

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

/** @internal */
export const GetDownloadQueueItemsRequest$outboundSchema: z.ZodType<
  GetDownloadQueueItemsRequest$Outbound,
  z.ZodTypeDef,
  GetDownloadQueueItemsRequest
> = 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(),
  itemId: z.array(z.number().int()),
}).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 getDownloadQueueItemsRequestToJSON(
  getDownloadQueueItemsRequest: GetDownloadQueueItemsRequest,
): string {
  return JSON.stringify(
    GetDownloadQueueItemsRequest$outboundSchema.parse(
      getDownloadQueueItemsRequest,
    ),
  );
}

/** @internal */
export const GetDownloadQueueItemsDecisionResult$inboundSchema: z.ZodType<
  GetDownloadQueueItemsDecisionResult,
  z.ZodTypeDef,
  unknown
> = z.object({
  availableBandwidth: z.number().int().optional(),
  directPlayDecisionCode: z.number().int().optional(),
  directPlayDecisionText: z.string().optional(),
  generalDecisionCode: z.number().int().optional(),
  generalDecisionText: z.string().optional(),
  mdeDecisionCode: z.number().int().optional(),
  mdeDecisionText: z.string().optional(),
  transcodeDecisionCode: z.number().int().optional(),
  transcodeDecisionText: z.string().optional(),
});

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

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

/** @internal */
export const GetDownloadQueueItemsTranscode$inboundSchema: z.ZodType<
  GetDownloadQueueItemsTranscode,
  z.ZodTypeDef,
  unknown
> = z.object({});

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

/** @internal */
export const GetDownloadQueueItemsDownloadQueueItem$inboundSchema: z.ZodType<
  GetDownloadQueueItemsDownloadQueueItem,
  z.ZodTypeDef,
  unknown
> = z.object({
  DecisionResult: z.lazy(() =>
    GetDownloadQueueItemsDecisionResult$inboundSchema
  ).optional(),
  error: z.string().optional(),
  id: z.number().int().optional(),
  key: z.string().optional(),
  queueId: z.number().int().optional(),
  status: GetDownloadQueueItemsStatus$inboundSchema.optional(),
  transcode: z.lazy(() => GetDownloadQueueItemsTranscode$inboundSchema)
    .optional(),
  TranscodeSession: shared.TranscodeSession$inboundSchema.optional(),
}).transform((v) => {
  return remap$(v, {
    "DecisionResult": "decisionResult",
    "TranscodeSession": "transcodeSession",
  });
});

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

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

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

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

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

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

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