/*
 * 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 enum GetBackgroundTasksType {
  Transcode = "transcode",
}

export type TranscodeJob = {
  generatorID?: number | undefined;
  key?: string | undefined;
  progress?: number | undefined;
  ratingKey?: string | undefined;
  /**
   * The number of seconds remaining in this job
   */
  remaining?: number | undefined;
  /**
   * The size of the result so far
   */
  size?: number | undefined;
  /**
   * The speed of the transcode; 1.0 means real-time
   */
  speed?: number | undefined;
  /**
   * The tag associated with the job.  This could be the tag containing the optimizer settings.
   */
  targetTagID?: number | undefined;
  thumb?: string | undefined;
  title?: string | undefined;
  type?: GetBackgroundTasksType | 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 GetBackgroundTasksMediaContainer = {
  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;
  transcodeJob?: Array<TranscodeJob> | undefined;
};

/**
 * OK
 */
export type GetBackgroundTasksResponseBody = {
  mediaContainer?: GetBackgroundTasksMediaContainer | undefined;
};

export type GetBackgroundTasksResponse = {
  /**
   * 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?: GetBackgroundTasksResponseBody | undefined;
};

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

/** @internal */
export const TranscodeJob$inboundSchema: z.ZodType<
  TranscodeJob,
  z.ZodTypeDef,
  unknown
> = z.object({
  generatorID: z.number().int().optional(),
  key: z.string().optional(),
  progress: z.number().optional(),
  ratingKey: z.string().optional(),
  remaining: z.number().int().optional(),
  size: z.number().int().optional(),
  speed: z.number().optional(),
  targetTagID: z.number().int().optional(),
  thumb: z.string().optional(),
  title: z.string().optional(),
  type: GetBackgroundTasksType$inboundSchema.optional(),
});

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

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

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

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

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

/** @internal */
export const GetBackgroundTasksResponse$inboundSchema: z.ZodType<
  GetBackgroundTasksResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  ContentType: z.string(),
  StatusCode: z.number().int(),
  RawResponse: z.instanceof(Response),
  object: z.lazy(() => GetBackgroundTasksResponseBody$inboundSchema).optional(),
}).transform((v) => {
  return remap$(v, {
    "ContentType": "contentType",
    "StatusCode": "statusCode",
    "RawResponse": "rawResponse",
  });
});

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