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

export type GetFirstCharactersGlobals = {
  /**
   * Indicates the client accepts the indicated media types
   */
  accepts?: shared.Accepts | undefined;
  /**
   * An opaque identifier unique to the client
   */
  clientIdentifier?: string | undefined;
  /**
   * The name of the client product
   */
  product?: string | undefined;
  /**
   * The version of the client application
   */
  version?: string | undefined;
  /**
   * The platform of the client
   */
  platform?: string | undefined;
  /**
   * The version of the platform
   */
  platformVersion?: string | undefined;
  /**
   * A relatively friendly name for the client device
   */
  device?: string | undefined;
  /**
   * A potentially less friendly identifier for the device model
   */
  model?: string | undefined;
  /**
   * The device vendor
   */
  deviceVendor?: string | undefined;
  /**
   * A friendly name for the client
   */
  deviceName?: string | undefined;
  /**
   * The marketplace on which the client application is distributed
   */
  marketplace?: string | undefined;
};

export type GetFirstCharactersRequest = {
  /**
   * Indicates the client accepts the indicated media types
   */
  accepts?: shared.Accepts | undefined;
  /**
   * An opaque identifier unique to the client
   */
  clientIdentifier?: string | undefined;
  /**
   * The name of the client product
   */
  product?: string | undefined;
  /**
   * The version of the client application
   */
  version?: string | undefined;
  /**
   * The platform of the client
   */
  platform?: string | undefined;
  /**
   * The version of the platform
   */
  platformVersion?: string | undefined;
  /**
   * A relatively friendly name for the client device
   */
  device?: string | undefined;
  /**
   * A potentially less friendly identifier for the device model
   */
  model?: string | undefined;
  /**
   * The device vendor
   */
  deviceVendor?: string | undefined;
  /**
   * A friendly name for the client
   */
  deviceName?: string | undefined;
  /**
   * The marketplace on which the client application is distributed
   */
  marketplace?: string | undefined;
  /**
   * Section identifier
   */
  sectionId: number;
  /**
   * The metadata type to filter on
   */
  type?: number | undefined;
  /**
   * The metadata type to filter on
   */
  sort?: number | undefined;
  /**
   * A querystring-based filtering language used to select subsets of media. Can be provided as an object with typed properties for type safety, or as a string for complex queries with operators and boolean logic.
   *
   * @remarks
   *
   * The query supports:
   * - Fields: integer, boolean, tag, string, date, language
   * - Operators: =, !=, ==, !==, <=, >=, >>=, <<= (varies by field type)
   * - Boolean operators: & (AND), , (OR), push/pop (parentheses), or=1 (explicit OR)
   * - Sorting: sort parameter with :desc, :nullsLast modifiers
   * - Grouping: group parameter
   * - Limits: limit parameter
   *
   * Examples:
   * - Object format: `{type: 4, sourceType: 2, title: "24"}` → `type=4&sourceType=2&title=24`
   * - String format: `type=4&sourceType=2&title==24` - type = 4 AND sourceType = 2 AND title = "24"
   * - Complex: `push=1&index=1&or=1&rating=2&pop=1&duration=10` - (index = 1 OR rating = 2) AND duration = 10
   *
   * See [API Info section](#section/API-Info/Media-Queries) for detailed information on building media queries.
   */
  mediaQuery?: shared.MediaQuery | undefined;
};

export type GetFirstCharactersDirectory = {
  key?: string | undefined;
  /**
   * The number of items starting with this character
   */
  size?: number | 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 GetFirstCharactersMediaContainer = {
  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;
  directory?: Array<GetFirstCharactersDirectory> | undefined;
};

/**
 * OK
 */
export type GetFirstCharactersResponseBody = {
  mediaContainer?: GetFirstCharactersMediaContainer | undefined;
};

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

/** @internal */
export type GetFirstCharactersRequest$Outbound = {
  accepts: string;
  "Client-Identifier"?: string | undefined;
  Product?: string | undefined;
  Version?: string | undefined;
  Platform?: string | undefined;
  "Platform-Version"?: string | undefined;
  Device?: string | undefined;
  Model?: string | undefined;
  "Device-Vendor"?: string | undefined;
  "Device-Name"?: string | undefined;
  Marketplace?: string | undefined;
  sectionId: number;
  type?: number | undefined;
  sort?: number | undefined;
  mediaQuery?: shared.MediaQuery$Outbound | undefined;
};

/** @internal */
export const GetFirstCharactersRequest$outboundSchema: z.ZodType<
  GetFirstCharactersRequest$Outbound,
  z.ZodTypeDef,
  GetFirstCharactersRequest
> = z.object({
  accepts: shared.Accepts$outboundSchema.default(shared.Accepts.ApplicationXml),
  clientIdentifier: z.string().optional(),
  product: z.string().optional(),
  version: z.string().optional(),
  platform: z.string().optional(),
  platformVersion: z.string().optional(),
  device: z.string().optional(),
  model: z.string().optional(),
  deviceVendor: z.string().optional(),
  deviceName: z.string().optional(),
  marketplace: z.string().optional(),
  sectionId: z.number().int(),
  type: z.number().int().optional(),
  sort: z.number().int().optional(),
  mediaQuery: shared.MediaQuery$outboundSchema.optional(),
}).transform((v) => {
  return remap$(v, {
    clientIdentifier: "Client-Identifier",
    product: "Product",
    version: "Version",
    platform: "Platform",
    platformVersion: "Platform-Version",
    device: "Device",
    model: "Model",
    deviceVendor: "Device-Vendor",
    deviceName: "Device-Name",
    marketplace: "Marketplace",
  });
});

export function getFirstCharactersRequestToJSON(
  getFirstCharactersRequest: GetFirstCharactersRequest,
): string {
  return JSON.stringify(
    GetFirstCharactersRequest$outboundSchema.parse(getFirstCharactersRequest),
  );
}

/** @internal */
export const GetFirstCharactersDirectory$inboundSchema: z.ZodType<
  GetFirstCharactersDirectory,
  z.ZodTypeDef,
  unknown
> = z.object({
  key: z.string().optional(),
  size: z.number().int().optional(),
  title: z.string().optional(),
});

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

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

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

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

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

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

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