/*
 * 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";

/**
 * 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 CreateDownloadQueueStatus {
  Deciding = "deciding",
  Waiting = "waiting",
  Processing = "processing",
  Done = "done",
  Error = "error",
}

export type CreateDownloadQueueDownloadQueue = {
  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?: CreateDownloadQueueStatus | 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 CreateDownloadQueueMediaContainer = {
  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<CreateDownloadQueueDownloadQueue> | undefined;
};

/**
 * OK
 */
export type CreateDownloadQueueResponseBody = {
  mediaContainer?: CreateDownloadQueueMediaContainer | undefined;
};

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

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

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

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

/** @internal */
export const CreateDownloadQueueMediaContainer$inboundSchema: z.ZodType<
  CreateDownloadQueueMediaContainer,
  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(() => CreateDownloadQueueDownloadQueue$inboundSchema),
  ).optional(),
}).transform((v) => {
  return remap$(v, {
    "DownloadQueue": "downloadQueue",
  });
});

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

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

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

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

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