/*
 * 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 { Device, Device$inboundSchema } from "./device.js";

/**
 * `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 DvrRequestHandlerSlashGetResponses200MediaContainerMediaContainer =
  {
    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;
    /**
     * A status indicator. If present and non-zero, indicates an error
     */
    status?: number | undefined;
  };

export type Dvr = {
  device?: Array<Device> | undefined;
  key?: string | undefined;
  language?: string | undefined;
  lineup?: string | undefined;
  uuid?: string | undefined;
};

export type DvrRequestHandlerSlashGetResponses200MediaContainer = {
  mediaContainer?:
    | DvrRequestHandlerSlashGetResponses200MediaContainerMediaContainer
    | undefined;
  dvr?: Array<Dvr> | undefined;
};

/**
 * OK
 */
export type DvrRequestHandlerSlashGetResponses200 = {
  mediaContainer?:
    | DvrRequestHandlerSlashGetResponses200MediaContainer
    | undefined;
};

/** @internal */
export const DvrRequestHandlerSlashGetResponses200MediaContainerMediaContainer$inboundSchema:
  z.ZodType<
    DvrRequestHandlerSlashGetResponses200MediaContainerMediaContainer,
    z.ZodTypeDef,
    unknown
  > = z.object({
    identifier: z.string().optional(),
    offset: z.number().int().optional(),
    size: z.number().int().optional(),
    totalSize: z.number().int().optional(),
    status: z.number().int().optional(),
  });

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

/** @internal */
export const Dvr$inboundSchema: z.ZodType<Dvr, z.ZodTypeDef, unknown> = z
  .object({
    Device: z.array(Device$inboundSchema).optional(),
    key: z.string().optional(),
    language: z.string().optional(),
    lineup: z.string().optional(),
    uuid: z.string().optional(),
  }).transform((v) => {
    return remap$(v, {
      "Device": "device",
    });
  });

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

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

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

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

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