/*
 * 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 Language = {
  /**
   * 3 letter language code
   */
  code?: string | undefined;
  title?: string | 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 GetAllLanguagesMediaContainer = {
  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;
  language?: Array<Language> | undefined;
};

/**
 * OK
 */
export type GetAllLanguagesResponseBody = {
  mediaContainer?: GetAllLanguagesMediaContainer | undefined;
};

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

/** @internal */
export const Language$inboundSchema: z.ZodType<
  Language,
  z.ZodTypeDef,
  unknown
> = z.object({
  code: z.string().optional(),
  title: z.string().optional(),
});

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

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

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

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

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

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