/*
 * 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 DirectoryPivot = {
  title?: string | undefined;
  type?: string | undefined;
  context?: string | undefined;
  id?: string | undefined;
  key?: string | undefined;
  symbol?: string | undefined;
};

export type Directory = {
  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;
  key?: string | undefined;
  lastAccessedAt?: number | undefined;
  pivot?: Array<DirectoryPivot> | undefined;
  share?: number | undefined;
  thumb?: string | undefined;
  titleBar?: string | undefined;
  additionalProperties?: { [k: string]: any } | undefined;
};

/** @internal */
export const DirectoryPivot$inboundSchema: z.ZodType<
  DirectoryPivot,
  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 directoryPivotFromJSON(
  jsonString: string,
): SafeParseResult<DirectoryPivot, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => DirectoryPivot$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'DirectoryPivot' from JSON`,
  );
}

/** @internal */
export const Directory$inboundSchema: z.ZodType<
  Directory,
  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(() => DirectoryPivot$inboundSchema)).optional(),
    share: z.number().int().optional(),
    thumb: z.string().optional(),
    titleBar: z.string().optional(),
  }).catchall(z.any()),
  "additionalProperties",
  true,
).transform((v) => {
  return remap$(v, {
    "Pivot": "pivot",
  });
});

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