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

export type SortPivot = {
  title?: string | undefined;
  type?: string | undefined;
  context?: string | undefined;
  id?: string | undefined;
  key?: string | undefined;
  symbol?: string | undefined;
};

/**
 * If present, this sort is the default and in this direction
 */
export enum DefaultEnum {
  Asc = "asc",
  Desc = "desc",
}

/**
 * This default diction of this sort
 */
export enum DefaultDirection {
  Asc = "asc",
  Desc = "desc",
}

/**
 * Each `Sort` object contains a description of the sort field.
 *
 * @remarks
 */
export type Sort = {
  /**
   * The title of the field.
   */
  title?: string | undefined;
  type?: string | undefined;
  art?: string | undefined;
  content?: boolean | undefined;
  filter?: string | undefined;
  hasPrefs?: boolean | undefined;
  hasStoreServices?: boolean | undefined;
  hubKey?: string | undefined;
  identifier?: string | undefined;
  /**
   * The key to use in the sort field to make items sort by this item
   */
  key?: string | undefined;
  lastAccessedAt?: number | undefined;
  pivot?: Array<SortPivot> | undefined;
  share?: number | undefined;
  thumb?: string | undefined;
  titleBar?: string | undefined;
  /**
   * If present, this sort is the default and in this direction
   */
  default?: DefaultEnum | undefined;
  /**
   * This default diction of this sort
   */
  defaultDirection?: DefaultDirection | undefined;
  /**
   * The key for sorting this field in reverse order
   */
  descKey?: string | undefined;
  /**
   * The key to use to get items sorted by this field and indexed by the first character
   */
  firstCharacterKey?: string | undefined;
  additionalProperties?: { [k: string]: any } | undefined;
};

/** @internal */
export const SortPivot$inboundSchema: z.ZodType<
  SortPivot,
  z.ZodTypeDef,
  unknown
> = z.object({
  title: z.string().optional(),
  type: z.string().optional(),
  context: z.string().optional(),
  id: z.string().optional(),
  key: z.string().optional(),
  symbol: z.string().optional(),
});

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

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

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

/** @internal */
export const Sort$inboundSchema: z.ZodType<Sort, z.ZodTypeDef, unknown> =
  collectExtraKeys$(
    z.object({
      title: z.string().optional(),
      type: z.string().optional(),
      art: z.string().optional(),
      content: z.boolean().optional(),
      filter: z.string().optional(),
      hasPrefs: z.boolean().optional(),
      hasStoreServices: z.boolean().optional(),
      hubKey: z.string().optional(),
      identifier: z.string().optional(),
      key: z.string().optional(),
      lastAccessedAt: z.number().int().optional(),
      Pivot: z.array(z.lazy(() => SortPivot$inboundSchema)).optional(),
      share: z.number().int().optional(),
      thumb: z.string().optional(),
      titleBar: z.string().optional(),
      default: DefaultEnum$inboundSchema.optional(),
      defaultDirection: DefaultDirection$inboundSchema.optional(),
      descKey: z.string().optional(),
      firstCharacterKey: z.string().optional(),
    }).catchall(z.any()),
    "additionalProperties",
    true,
  ).transform((v) => {
    return remap$(v, {
      "Pivot": "pivot",
    });
  });

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