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

export type MetadatumResponse = {
  /**
   * 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 HistoryAllGetResponses200MediaContainer = {
  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<MetadatumResponse> | undefined;
};

/**
 * OK
 */
export type HistoryAllGetResponses200 = {
  mediaContainer?: HistoryAllGetResponses200MediaContainer | undefined;
};

/** @internal */
export const MetadatumResponse$inboundSchema: z.ZodType<
  MetadatumResponse,
  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 metadatumResponseFromJSON(
  jsonString: string,
): SafeParseResult<MetadatumResponse, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => MetadatumResponse$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'MetadatumResponse' from JSON`,
  );
}

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

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

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

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