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

/**
 * - `0`: The country is divided into regions, and following the key will lead to a list of regions.
 *
 * @remarks
 * - `1`: The county is divided by postal codes, and an example code is returned in `example`.
 * - `2`: The country has a single postal code, returned in `example`.
 */
export enum Flavor {
  Zero = 0,
  One = 1,
  Two = 2,
}

export type GetCountriesCountry = {
  /**
   * Three letter code
   */
  code?: string | undefined;
  example?: string | undefined;
  /**
   * - `0`: The country is divided into regions, and following the key will lead to a list of regions.
   *
   * @remarks
   * - `1`: The county is divided by postal codes, and an example code is returned in `example`.
   * - `2`: The country has a single postal code, returned in `example`.
   */
  flavor?: Flavor | undefined;
  key?: string | undefined;
  /**
   * Three letter language code
   */
  language?: string | undefined;
  /**
   * The title of the language
   */
  languageTitle?: string | undefined;
  title?: string | undefined;
  type?: 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 GetCountriesMediaContainer = {
  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;
  country?: Array<GetCountriesCountry> | undefined;
};

/**
 * OK
 */
export type GetCountriesResponseBody = {
  mediaContainer?: GetCountriesMediaContainer | undefined;
};

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

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

/** @internal */
export const GetCountriesCountry$inboundSchema: z.ZodType<
  GetCountriesCountry,
  z.ZodTypeDef,
  unknown
> = z.object({
  code: z.string().optional(),
  example: z.string().optional(),
  flavor: Flavor$inboundSchema.optional(),
  key: z.string().optional(),
  language: z.string().optional(),
  languageTitle: z.string().optional(),
  title: z.string().optional(),
  type: z.string().optional(),
});

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

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

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

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

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

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