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

/**
 * `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 ListDVRsMediaContainerMediaContainer = {
  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 ListDVRsDVR = {
  device?: Array<shared.Device> | undefined;
  key?: string | undefined;
  language?: string | undefined;
  lineup?: string | undefined;
  uuid?: string | undefined;
};

export type ListDVRsMediaContainer = {
  mediaContainer?: ListDVRsMediaContainerMediaContainer | undefined;
  dvr?: Array<ListDVRsDVR> | undefined;
};

/**
 * OK
 */
export type ListDVRsResponseBody = {
  mediaContainer?: ListDVRsMediaContainer | undefined;
};

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

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

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

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

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

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

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

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