/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow strict-local
 * @format
 */

// The 'prebuilt' flavor will use the prebuilt shell binary (and the JavaScript embedded in it).
// The 'dev' flavor will use a stock Electron binary and run the shell code from the `electron/` directory.
type DebuggerShellFlavor = "prebuilt" | "dev";

declare function unstable_spawnDebuggerShellWithArgs(
  args: string[],
  $$PARAM_1$$?: Readonly<{
    // In 'syncAndExit' mode, the current process will block until the spawned process exits, and then it will exit
    // with the same exit code as the spawned process.
    // In 'detached' mode, the spawned process will be detached from the current process and the current process will
    // continue to run normally.
    mode?: "syncThenExit" | "detached",
    flavor?: DebuggerShellFlavor,
    prebuiltBinaryPath?: ?string,
    silent?: boolean,
  }>,
): Promise<void>;

export type DebuggerShellPreparationResult = Readonly<{
  code:
    | "success"
    | "not_implemented"
    | "likely_offline"
    | "platform_not_supported"
    | "possible_corruption"
    | "unexpected_error",
  humanReadableMessage?: string,
  verboseInfo?: string,
}>;

/**
 * Attempts to prepare the debugger shell for use and returns a coded result
 * that can be used to advise the user on how to proceed in case of failure.
 * In particular, this function will attempt to download and extract an
 * appropriate binary for the "prebuilt" flavor.
 *
 * This function should be called early during dev server startup, in parallel
 * with other initialization steps, so that the debugger shell is ready to use
 * instantly when the user tries to open it (and conversely, the user is
 * informed ASAP if it is not ready to use).
 */
declare function unstable_prepareDebuggerShell($$PARAM_0$$?: {
  prebuiltBinaryPath?: ?string,
  flavor?: DebuggerShellFlavor,
}): Promise<DebuggerShellPreparationResult>;

export { unstable_spawnDebuggerShellWithArgs, unstable_prepareDebuggerShell };
