/*
 * 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 {
  collectExtraKeys as collectExtraKeys$,
  safeParse,
} from "../../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import { Metadata, Metadata$inboundSchema } from "./metadata.js";

export type Hub = {
  /**
   * A title for this grouping of content
   */
  title?: string | undefined;
  /**
   * The type of the items contained in this hub, or possibly `mixed` if there are multiple types
   */
  type?: string | undefined;
  context?: string | undefined;
  /**
   * A unique identifier for the hub
   */
  hubIdentifier?: string | undefined;
  /**
   * A key at which the exact content currently displayed can be fetched again. This is particularly important when a hub is marked as random and requesting the `key` may get different results. It's otherwise optional.
   *
   * @remarks
   */
  hubKey?: string | undefined;
  /**
   * The key at which all of the content for this hub can be retrieved
   */
  key?: string | undefined;
  metadata?: Array<Metadata> | undefined;
  /**
   * "A boolean indicating that the hub contains more than what's included in the current response."
   *
   * @remarks
   */
  more?: boolean | undefined;
  /**
   * Indicating if the hub should be promoted to the user's homescreen
   */
  promoted?: boolean | undefined;
  /**
   * Indicating that the contents of the hub may change on each request
   */
  random?: boolean | undefined;
  size?: number | undefined;
  /**
   * A suggestion on how this hub's contents might be displayed by a client. Some examples include `hero`, `list`, `spotlight`, and `upsell`
   */
  style?: string | undefined;
  /**
   * The subtype of the items contained in this hub, or possibly `mixed` if there are multiple types
   */
  subtype?: string | undefined;
  totalSize?: number | undefined;
  additionalProperties?: { [k: string]: any } | undefined;
};

/** @internal */
export const Hub$inboundSchema: z.ZodType<Hub, z.ZodTypeDef, unknown> =
  collectExtraKeys$(
    z.object({
      title: z.string().optional(),
      type: z.string().optional(),
      context: z.string().optional(),
      hubIdentifier: z.string().optional(),
      hubKey: z.string().optional(),
      key: z.string().optional(),
      Metadata: z.array(Metadata$inboundSchema).optional(),
      more: z.boolean().optional(),
      promoted: z.boolean().optional(),
      random: z.boolean().optional(),
      size: z.number().int().optional(),
      style: z.string().optional(),
      subtype: z.string().optional(),
      totalSize: z.number().int().optional(),
    }).catchall(z.any()),
    "additionalProperties",
    true,
  ).transform((v) => {
    return remap$(v, {
      "Metadata": "metadata",
    });
  });

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