/*
 * 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 ListPlaybackHistoryGlobals = {
  /**
   * 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 ListPlaybackHistoryRequest = {
  /**
   * 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 account id to restrict view history
   */
  accountID?: number | undefined;
  /**
   * The time period to restrict history (typically of the form `viewedAt>=12456789`)
   */
  viewedAt?: number | undefined;
  /**
   * The library section id to restrict view history
   */
  librarySectionID?: number | undefined;
  /**
   * The metadata item to restrict view history (can provide the id for a show to see all of that show's view history).  Note this is translated to `metadata_items.id`, `parents.id`, or `grandparents.id` internally depending on the metadata type.
   */
  metadataItemID?: number | undefined;
  /**
   * The field on which to sort.  Multiple orderings can be specified separated by `,` and the direction specified following a `:` (`desc` or `asc`; `asc` is assumed if not provided).  Note `metadataItemID` may not be used here.
   */
  sort?: Array<string> | undefined;
};

export type ListPlaybackHistoryMetadatum = {
  /**
   * The account id of this playback
   */
  accountID?: number | undefined;
  /**
   * The device id which played the item
   */
  deviceID?: number | undefined;
  /**
   * The key for this individual history item
   */
  historyKey?: string | undefined;
  /**
   * The metadata key for the item played
   */
  key?: string | undefined;
  /**
   * The library section id containing the item played
   */
  librarySectionID?: string | undefined;
  /**
   * The originally available at of the item played
   */
  originallyAvailableAt?: string | undefined;
  /**
   * The rating key for the item played
   */
  ratingKey?: string | undefined;
  /**
   * The thumb of the item played
   */
  thumb?: string | undefined;
  /**
   * The title of the item played
   */
  title?: string | undefined;
  /**
   * The metadata type of the item played
   */
  type?: string | undefined;
  /**
   * The time when the item was played
   */
  viewedAt?: number | 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 ListPlaybackHistoryMediaContainer = {
  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;
  metadata?: Array<ListPlaybackHistoryMetadatum> | undefined;
};

/**
 * OK
 */
export type ListPlaybackHistoryResponseBody = {
  mediaContainer?: ListPlaybackHistoryMediaContainer | undefined;
};

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

/** @internal */
export type ListPlaybackHistoryRequest$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;
  accountID?: number | undefined;
  viewedAt?: number | undefined;
  librarySectionID?: number | undefined;
  metadataItemID?: number | undefined;
  sort?: Array<string> | undefined;
};

/** @internal */
export const ListPlaybackHistoryRequest$outboundSchema: z.ZodType<
  ListPlaybackHistoryRequest$Outbound,
  z.ZodTypeDef,
  ListPlaybackHistoryRequest
> = 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(),
  accountID: z.number().int().optional(),
  viewedAt: z.number().int().optional(),
  librarySectionID: z.number().int().optional(),
  metadataItemID: z.number().int().optional(),
  sort: z.array(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 listPlaybackHistoryRequestToJSON(
  listPlaybackHistoryRequest: ListPlaybackHistoryRequest,
): string {
  return JSON.stringify(
    ListPlaybackHistoryRequest$outboundSchema.parse(listPlaybackHistoryRequest),
  );
}

/** @internal */
export const ListPlaybackHistoryMetadatum$inboundSchema: z.ZodType<
  ListPlaybackHistoryMetadatum,
  z.ZodTypeDef,
  unknown
> = z.object({
  accountID: z.number().int().optional(),
  deviceID: z.number().int().optional(),
  historyKey: z.string().optional(),
  key: z.string().optional(),
  librarySectionID: z.string().optional(),
  originallyAvailableAt: z.string().optional(),
  ratingKey: z.string().optional(),
  thumb: z.string().optional(),
  title: z.string().optional(),
  type: z.string().optional(),
  viewedAt: z.number().int().optional(),
});

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

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

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

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

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

/** @internal */
export const ListPlaybackHistoryResponse$inboundSchema: z.ZodType<
  ListPlaybackHistoryResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  ContentType: z.string(),
  StatusCode: z.number().int(),
  RawResponse: z.instanceof(Response),
  object: z.lazy(() => ListPlaybackHistoryResponseBody$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 listPlaybackHistoryResponseFromJSON(
  jsonString: string,
): SafeParseResult<ListPlaybackHistoryResponse, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ListPlaybackHistoryResponse$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ListPlaybackHistoryResponse' from JSON`,
  );
}
