/*
 * 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 ListHubsGlobals = {
  /**
   * 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 ListHubsRequest = {
  /**
   * 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;
  /**
   * The section ID for the hubs to reorder
   */
  sectionId: number;
  /**
   * Restrict hubs to ones relevant to the provided metadata item
   */
  metadataItemId?: number | undefined;
};

/**
 * Whether this hub is visible on the home screen
 *
 * @remarks
 *   - all: Visible to all users
 *   - none: Visible to no users
 *   - admin: Visible to only admin users
 *   - shared: Visible to shared users
 */
export enum HomeVisibility {
  All = "all",
  None = "none",
  Admin = "admin",
  Shared = "shared",
}

/**
 * The visibility of this hub in recommendations:
 *
 * @remarks
 *   - all: Visible to all users
 *   - none: Visible to no users
 *   - admin: Visible to only admin users
 *   - shared: Visible to shared users
 */
export enum RecommendationsVisibility {
  All = "all",
  None = "none",
  Admin = "admin",
  Shared = "shared",
}

export type Hub = {
  /**
   * Whether this hub is visible on the home screen
   *
   * @remarks
   *   - all: Visible to all users
   *   - none: Visible to no users
   *   - admin: Visible to only admin users
   *   - shared: Visible to shared users
   */
  homeVisibility?: HomeVisibility | undefined;
  /**
   * The identifier for this hub
   */
  identifier?: string | undefined;
  /**
   * Whether this hub is visible to admin user home
   */
  promotedToOwnHome?: boolean | undefined;
  /**
   * Whether this hub is promoted to all for recommendations
   */
  promotedToRecommended?: boolean | undefined;
  /**
   * Whether this hub is visible to shared user's home
   */
  promotedToSharedHome?: boolean | undefined;
  /**
   * The visibility of this hub in recommendations:
   *
   * @remarks
   *   - all: Visible to all users
   *   - none: Visible to no users
   *   - admin: Visible to only admin users
   *   - shared: Visible to shared users
   */
  recommendationsVisibility?: RecommendationsVisibility | undefined;
  /**
   * The title of this hub
   */
  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 ListHubsMediaContainer = {
  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;
  hub?: Array<Hub> | undefined;
};

/**
 * OK
 */
export type ListHubsResponseBody = {
  mediaContainer?: ListHubsMediaContainer | undefined;
};

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

/** @internal */
export type ListHubsRequest$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;
  metadataItemId?: number | undefined;
};

/** @internal */
export const ListHubsRequest$outboundSchema: z.ZodType<
  ListHubsRequest$Outbound,
  z.ZodTypeDef,
  ListHubsRequest
> = 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(),
  metadataItemId: z.number().int().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 listHubsRequestToJSON(
  listHubsRequest: ListHubsRequest,
): string {
  return JSON.stringify(ListHubsRequest$outboundSchema.parse(listHubsRequest));
}

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

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

/** @internal */
export const Hub$inboundSchema: z.ZodType<Hub, z.ZodTypeDef, unknown> = z
  .object({
    homeVisibility: HomeVisibility$inboundSchema.optional(),
    identifier: z.string().optional(),
    promotedToOwnHome: z.boolean().optional(),
    promotedToRecommended: z.boolean().optional(),
    promotedToSharedHome: z.boolean().optional(),
    recommendationsVisibility: RecommendationsVisibility$inboundSchema
      .optional(),
    title: z.string().optional(),
  });

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

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

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

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

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

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