/*
 * 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 CreatePlayQueueGlobals = {
  /**
   * 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 type of play queue to create
 */
export enum CreatePlayQueueType {
  Audio = "audio",
  Video = "video",
  Photo = "photo",
}

export type CreatePlayQueueRequest = {
  /**
   * 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 content URI for what we're playing.
   */
  uri?: string | undefined;
  /**
   * the ID of the playlist we're playing.
   */
  playlistID?: number | undefined;
  /**
   * The type of play queue to create
   */
  type: CreatePlayQueueType;
  /**
   * The key of the first item to play, defaults to the first in the play queue.
   */
  key?: string | undefined;
  /**
   * Whether to shuffle the playlist, defaults to 0.
   */
  shuffle?: shared.BoolInt | undefined;
  /**
   * If the PQ is bigger than the window, fill any empty space with wraparound items, defaults to 0.
   */
  repeat?: shared.BoolInt | undefined;
  /**
   * Whether to create a continuous play queue (e.g. from an episode), defaults to 0.
   */
  continuous?: shared.BoolInt | undefined;
  /**
   * Number of trailers to prepend a movie with not including the pre-roll. If omitted the pre-roll will not be returned in the play queue. When resuming a movie `extrasPrefixCount` should be omitted as a parameter instead of passing 0.
   */
  extrasPrefixCount?: number | undefined;
  /**
   * Only applies to queues of type photo, whether to retrieve all descendent photos from an album or section, defaults to 1.
   */
  recursive?: shared.BoolInt | undefined;
  /**
   * Only applies to queues of type show or seasons, whether to return a queue that is started on the On Deck episode if one exists. Otherwise begins the play queue on the beginning of the show or season.
   */
  onDeck?: shared.BoolInt | 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 CreatePlayQueueMediaContainer = {
  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;
  /**
   * The ID of the play queue, which is used in subsequent requests.
   */
  playQueueID?: number | undefined;
  /**
   * Defines where the "Up Next" region starts
   */
  playQueueLastAddedItemID?: string | undefined;
  /**
   * The queue item ID of the currently selected  item.
   */
  playQueueSelectedItemID?: number | undefined;
  /**
   * The offset of the selected item in the play queue, from the beginning of the queue.
   */
  playQueueSelectedItemOffset?: number | undefined;
  /**
   * The metadata item ID of the currently selected item (matches `ratingKey` attribute in metadata item if the media provider is a library).
   */
  playQueueSelectedMetadataItemID?: number | undefined;
  /**
   * Whether or not the queue is shuffled.
   */
  playQueueShuffled?: boolean | undefined;
  /**
   * The original URI used to create the play queue.
   */
  playQueueSourceURI?: string | undefined;
  /**
   * The total number of items in the play queue.
   */
  playQueueTotalCount?: number | undefined;
  /**
   * The version of the play queue. It increments every time a change is made to the play queue to assist clients in knowing when to refresh.
   */
  playQueueVersion?: number | undefined;
};

/**
 * OK
 */
export type CreatePlayQueueResponseBody = {
  mediaContainer?: CreatePlayQueueMediaContainer | undefined;
};

export type CreatePlayQueueResponse = {
  /**
   * 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?: CreatePlayQueueResponseBody | undefined;
  headers: { [k: string]: Array<string> };
};

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

/** @internal */
export type CreatePlayQueueRequest$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;
  uri?: string | undefined;
  playlistID?: number | undefined;
  type: string;
  key?: string | undefined;
  shuffle: number;
  repeat: number;
  continuous: number;
  extrasPrefixCount?: number | undefined;
  recursive: number;
  onDeck: number;
};

/** @internal */
export const CreatePlayQueueRequest$outboundSchema: z.ZodType<
  CreatePlayQueueRequest$Outbound,
  z.ZodTypeDef,
  CreatePlayQueueRequest
> = 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(),
  uri: z.string().optional(),
  playlistID: z.number().int().optional(),
  type: CreatePlayQueueType$outboundSchema,
  key: z.string().optional(),
  shuffle: shared.BoolInt$outboundSchema.default(shared.BoolInt.False),
  repeat: shared.BoolInt$outboundSchema.default(shared.BoolInt.False),
  continuous: shared.BoolInt$outboundSchema.default(shared.BoolInt.False),
  extrasPrefixCount: z.number().int().optional(),
  recursive: shared.BoolInt$outboundSchema.default(shared.BoolInt.False),
  onDeck: shared.BoolInt$outboundSchema.default(shared.BoolInt.False),
}).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 createPlayQueueRequestToJSON(
  createPlayQueueRequest: CreatePlayQueueRequest,
): string {
  return JSON.stringify(
    CreatePlayQueueRequest$outboundSchema.parse(createPlayQueueRequest),
  );
}

/** @internal */
export const CreatePlayQueueMediaContainer$inboundSchema: z.ZodType<
  CreatePlayQueueMediaContainer,
  z.ZodTypeDef,
  unknown
> = z.object({
  identifier: z.string().optional(),
  offset: z.number().int().optional(),
  size: z.number().int().optional(),
  totalSize: z.number().int().optional(),
  playQueueID: z.number().int().optional(),
  playQueueLastAddedItemID: z.string().optional(),
  playQueueSelectedItemID: z.number().int().optional(),
  playQueueSelectedItemOffset: z.number().int().optional(),
  playQueueSelectedMetadataItemID: z.number().int().optional(),
  playQueueShuffled: z.boolean().optional(),
  playQueueSourceURI: z.string().optional(),
  playQueueTotalCount: z.number().int().optional(),
  playQueueVersion: z.number().int().optional(),
});

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

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

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

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

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