/*
 * 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 {
  collectExtraKeys as collectExtraKeys$,
  safeParse,
} from "../../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export enum MediaContainerWithArtworkType {
  Image = "image",
}

export type MediaContainerWithArtworkMetadatum = {
  /**
   * The title of the item
   */
  title?: string | undefined;
  type?: MediaContainerWithArtworkType | undefined;
  /**
   * The path to the artwork
   */
  key?: string | undefined;
  additionalProperties?: { [k: string]: any } | 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 MediaContainerWithArtworkMediaContainer = {
  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<MediaContainerWithArtworkMetadatum> | undefined;
};

export type MediaContainerWithArtwork = {
  mediaContainer?: MediaContainerWithArtworkMediaContainer | undefined;
};

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

/** @internal */
export const MediaContainerWithArtworkMetadatum$inboundSchema: z.ZodType<
  MediaContainerWithArtworkMetadatum,
  z.ZodTypeDef,
  unknown
> = collectExtraKeys$(
  z.object({
    title: z.string().optional(),
    type: MediaContainerWithArtworkType$inboundSchema.optional(),
    key: z.string().optional(),
  }).catchall(z.any()),
  "additionalProperties",
  true,
);

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

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

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

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

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