/*
 * 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 GetDownloadQueueGlobals = {
  /**
   * 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 GetDownloadQueueRequest = {
  /**
   * 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 state of this queue
 *
 * @remarks
 *   - deciding: At least one item is still being decided
 *   - waiting: At least one item is waiting for transcode and none are currently transcoding
 *   - processing: At least one item is being transcoded
 *   - done: All items are available (or potentially expired)
 *   - error: At least one item has encountered an error
 */
export enum GetDownloadQueueStatus {
  Deciding = "deciding",
  Waiting = "waiting",
  Processing = "processing",
  Done = "done",
  Error = "error",
}

export type GetDownloadQueueDownloadQueue = {
  id?: number | undefined;
  itemCount?: number | undefined;
  /**
   * The state of this queue
   *
   * @remarks
   *   - deciding: At least one item is still being decided
   *   - waiting: At least one item is waiting for transcode and none are currently transcoding
   *   - processing: At least one item is being transcoded
   *   - done: All items are available (or potentially expired)
   *   - error: At least one item has encountered an error
   */
  status?: GetDownloadQueueStatus | 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 GetDownloadQueueMediaContainer = {
  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;
  downloadQueue?: Array<GetDownloadQueueDownloadQueue> | undefined;
};

/**
 * OK
 */
export type GetDownloadQueueResponseBody = {
  mediaContainer?: GetDownloadQueueMediaContainer | undefined;
};

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

/** @internal */
export type GetDownloadQueueRequest$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;
};

/** @internal */
export const GetDownloadQueueRequest$outboundSchema: z.ZodType<
  GetDownloadQueueRequest$Outbound,
  z.ZodTypeDef,
  GetDownloadQueueRequest
> = 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(),
}).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 getDownloadQueueRequestToJSON(
  getDownloadQueueRequest: GetDownloadQueueRequest,
): string {
  return JSON.stringify(
    GetDownloadQueueRequest$outboundSchema.parse(getDownloadQueueRequest),
  );
}

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

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

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

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

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

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

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

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

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