/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v3";
import { safeParse } from "../lib/schemas.js";
import { ClosedEnum } from "../types/enums.js";
import { Result as SafeParseResult } from "../types/fp.js";
import * as types from "../types/primitives.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

/**
 * String indicating the type of file tree entry.
 */
export const FileTreeType = {
  Directory: "directory",
  File: "file",
  Invalid: "invalid",
  Lambda: "lambda",
  Middleware: "middleware",
  Symlink: "symlink",
} as const;
/**
 * String indicating the type of file tree entry.
 */
export type FileTreeType = ClosedEnum<typeof FileTreeType>;

/**
 * A deployment file tree entry
 */
export type FileTree = {
  /**
   * The name of the file tree entry
   */
  name: string;
  /**
   * String indicating the type of file tree entry.
   */
  type: FileTreeType;
  /**
   * The unique identifier of the file (only valid for the `file` type)
   */
  uid?: string | undefined;
  /**
   * The list of children files of the directory (only valid for the `directory` type)
   */
  children?: Array<FileTree> | undefined;
  /**
   * The content-type of the file (only valid for the `file` type)
   */
  contentType?: string | undefined;
  /**
   * The file "mode" indicating file type and permissions.
   */
  mode: number;
};

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

/** @internal */
export const FileTree$inboundSchema: z.ZodType<
  FileTree,
  z.ZodTypeDef,
  unknown
> = z.object({
  name: types.string(),
  type: FileTreeType$inboundSchema,
  uid: types.optional(types.string()),
  children: types.optional(z.array(z.lazy(() => FileTree$inboundSchema))),
  contentType: types.optional(types.string()),
  mode: types.number(),
});

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