/* auto-generated by NAPI-RS */
/* eslint-disable */
/** Error from batch import rewriting */
export interface BatchRewriteError {
  /** The file path that had an error */
  path: string;
  /** The error message */
  message: string;
}

/** Result of rewriting imports in multiple files */
export interface BatchRewriteResult {
  /** Files that were modified */
  modifiedFiles: Array<string>;
  /** Files that had errors */
  errors: Array<BatchRewriteError>;
}

/** Configuration options passed from JavaScript to Rust. */
export interface CliOptions {
  lint: (err: Error | null) => Promise<JsCommandResolvedResult>;
  fmt: (err: Error | null) => Promise<JsCommandResolvedResult>;
  vite: (err: Error | null) => Promise<JsCommandResolvedResult>;
  test: (err: Error | null) => Promise<JsCommandResolvedResult>;
  pack: (err: Error | null) => Promise<JsCommandResolvedResult>;
  doc: (err: Error | null) => Promise<JsCommandResolvedResult>;
  cwd?: string;
  /** CLI arguments (should be process.argv.slice(2) from JavaScript) */
  args?: Array<string>;
  /** Read the vite.config.ts in the Node.js side and return the `lint` and `fmt` config JSON string back to the Rust side */
  resolveUniversalViteConfig: (err: Error | null, arg: string) => Promise<string>;
}

/**
 * Detect the workspace root and package manager type and version
 *
 * ## Parameters
 *
 * - `cwd`: The current working directory to detect the workspace root
 *
 * ## Returns
 *
 * Returns a `DetectWorkspaceResult` containing:
 * - The name of the package manager
 * - The version of the package manager
 * - Whether the workspace is a monorepo
 * - The workspace root, where the package.json file is located.
 *
 * ## Example
 *
 * ```javascript
 * const result = await detectWorkspace("/path/to/workspace");
 * console.log(`Package manager name: ${result.packageManagerName}`);
 * console.log(`Package manager version: ${result.packageManagerVersion}`);
 * console.log(`Is monorepo: ${result.isMonorepo}`);
 * console.log(`Workspace root: ${result.root}`);
 * ```
 */
export declare function detectWorkspace(cwd: string): Promise<DetectWorkspaceResult>;

export interface DetectWorkspaceResult {
  packageManagerName?: string;
  packageManagerVersion?: string;
  isMonorepo: boolean;
  root?: string;
}

/**
 * Download a package manager
 *
 * ## Parameters
 *
 * - `options`: Configuration for the package manager to download, including:
 *   - `name`: The name of the package manager
 *   - `version`: The version of the package manager
 *   - `expected_hash`: The expected hash of the package manager
 *
 * ## Returns
 *
 * Returns a `DownloadPackageManagerResult` containing:
 * - The name of the package manager
 * - The install directory of the package manager
 * - The binary prefix of the package manager
 * - The package name of the package manager
 * - The version of the package manager
 *
 * ## Example
 *
 * ```javascript
 * const result = await downloadPackageManager({
 *   name: "pnpm",
 *   version: "latest",
 * });
 * console.log(`Package manager name: ${result.name}`);
 * console.log(`Package manager install directory: ${result.installDir}`);
 * console.log(`Package manager binary prefix: ${result.binPrefix}`);
 * console.log(`Package manager package name: ${result.packageName}`);
 * console.log(`Package manager version: ${result.version}`);
 * ```
 */
export declare function downloadPackageManager(
  options: DownloadPackageManagerOptions,
): Promise<DownloadPackageManagerResult>;

export interface DownloadPackageManagerOptions {
  name: string;
  version: string;
  expectedHash?: string;
}

export interface DownloadPackageManagerResult {
  name: string;
  installDir: string;
  binPrefix: string;
  packageName: string;
  version: string;
}

/** Result returned by JavaScript resolver functions. */
export interface JsCommandResolvedResult {
  binPath: string;
  envs: Record<string, string>;
}

/**
 * Merge JSON configuration file into vite config file
 *
 * This function reads the files from disk and merges the JSON config
 * into the vite configuration file.
 *
 * # Arguments
 *
 * * `vite_config_path` - Path to the vite.config.ts or vite.config.js file
 * * `json_config_path` - Path to the JSON config file (e.g., .oxlintrc, .oxfmtrc)
 * * `config_key` - The key to use in the vite config (e.g., "lint", "fmt")
 *
 * # Returns
 *
 * Returns a `MergeJsonConfigResult` containing:
 * - `content`: The updated vite config content
 * - `updated`: Whether any changes were made
 * - `usesFunctionCallback`: Whether the config uses a function callback
 *
 * # Example
 *
 * ```javascript
 * const result = mergeJsonConfig('vite.config.ts', '.oxlintrc', 'lint');
 * if (result.updated) {
 *     fs.writeFileSync('vite.config.ts', result.content);
 * }
 * ```
 */
export declare function mergeJsonConfig(
  viteConfigPath: string,
  jsonConfigPath: string,
  configKey: string,
): MergeJsonConfigResult;

/** Result of merging JSON config into vite config */
export interface MergeJsonConfigResult {
  /** The updated vite config content */
  content: string;
  /** Whether any changes were made */
  updated: boolean;
  /** Whether the config uses a function callback */
  usesFunctionCallback: boolean;
}

/**
 * Merge tsdown config into vite config by importing it
 *
 * This function adds an import statement for the tsdown config file
 * and adds `pack: packConfig` to the defineConfig.
 *
 * # Arguments
 *
 * * `vite_config_path` - Path to the vite.config.ts or vite.config.js file
 * * `tsdown_config_path` - Relative path to the tsdown.config.ts file (e.g., "./tsdown.config.ts")
 *
 * # Returns
 *
 * Returns a `MergeJsonConfigResult` containing:
 * - `content`: The updated vite config content
 * - `updated`: Whether any changes were made
 * - `usesFunctionCallback`: Whether the config uses a function callback
 *
 * # Example
 *
 * ```javascript
 * const result = mergeTsdownConfig('vite.config.ts', './tsdown.config.ts');
 * if (result.updated) {
 *     fs.writeFileSync('vite.config.ts', result.content);
 * }
 * ```
 */
export declare function mergeTsdownConfig(
  viteConfigPath: string,
  tsdownConfigPath: string,
): MergeJsonConfigResult;

/** Access modes for a path. */
export interface PathAccess {
  /** Whether the path was read */
  read: boolean;
  /** Whether the path was written */
  write: boolean;
  /** Whether the path was read as a directory */
  readDir: boolean;
}

/**
 * Rewrite ESLint scripts: rename `eslint` → `vp lint` and strip ESLint-only flags.
 *
 * Uses brush-parser to parse shell commands, so it correctly handles env var prefixes,
 * compound commands (`&&`, `||`, `|`), and quoted arguments.
 *
 * # Arguments
 *
 * * `scripts_json` - The scripts section as a JSON string
 *
 * # Returns
 *
 * * `updated` - The updated scripts JSON string, or `null` if no changes were made
 */
export declare function rewriteEslint(scriptsJson: string): string | null;

/**
 * Rewrite imports in all TypeScript/JavaScript files under a directory
 *
 * This function finds all TypeScript and JavaScript files in the specified directory
 * (respecting `.gitignore` rules), applies the import rewrite rules to each file,
 * and writes the modified content back to disk.
 *
 * # Arguments
 *
 * * `root` - The root directory to search for files
 *
 * # Returns
 *
 * Returns a `BatchRewriteResult` containing:
 * - `modifiedFiles`: Files that were changed
 * - `errors`: Files that had errors during processing
 *
 * # Example
 *
 * ```javascript
 * const result = rewriteImportsInDirectory('./src');
 * console.log(`Modified ${result.modifiedFiles.length} files`);
 * for (const file of result.modifiedFiles) {
 *     console.log(`  ${file}`);
 * }
 * ```
 */
export declare function rewriteImportsInDirectory(root: string): BatchRewriteResult;

/**
 * Rewrite Prettier scripts: rename `prettier` → `vp fmt` and strip Prettier-only flags.
 *
 * Uses brush-parser to parse shell commands, so it correctly handles env var prefixes,
 * compound commands (`&&`, `||`, `|`), and quoted arguments.
 *
 * # Arguments
 *
 * * `scripts_json` - The scripts section as a JSON string
 *
 * # Returns
 *
 * * `updated` - The updated scripts JSON string, or `null` if no changes were made
 */
export declare function rewritePrettier(scriptsJson: string): string | null;

/**
 * Rewrite scripts json content using rules from rules_yaml
 *
 * # Arguments
 *
 * * `scripts_json` - The scripts section of the package.json file as a JSON string
 * * `rules_yaml` - The ast-grep rules.yaml as a YAML string
 *
 * # Returns
 *
 * * `updated` - The updated scripts section of the package.json file as a JSON string, or `null` if no updates were made
 *
 * # Example
 *
 * ```javascript
 * const updated = rewriteScripts("scripts section json content here", "ast-grep rules yaml content here");
 * console.log(`Updated: ${updated}`);
 * ```
 */
export declare function rewriteScripts(scriptsJson: string, rulesYaml: string): string | null;

/**
 * Main entry point for the CLI, called from JavaScript.
 *
 * This is an async function that spawns a new thread for the non-Send async code
 * from vite_task, while allowing the NAPI async context to continue running
 * and process JavaScript callbacks (via ThreadsafeFunction).
 */
export declare function run(options: CliOptions): Promise<number>;

/**
 * Run a command with fspy tracking, callable from JavaScript.
 *
 * This function wraps `vite_command::run_command_with_fspy` to provide
 * a JavaScript-friendly interface for executing commands and tracking
 * their file system accesses.
 *
 * ## Parameters
 *
 * - `options`: Configuration for the command to run, including:
 *   - `bin_name`: The name of the binary to execute
 *   - `args`: Command line arguments
 *   - `envs`: Environment variables
 *   - `cwd`: Working directory
 *
 * ## Returns
 *
 * Returns a `RunCommandResult` containing:
 * - The exit code of the command
 * - A map of file paths accessed and their access modes
 *
 * ## Example
 *
 * ```javascript
 * const result = await runCommand({
 *   binName: "node",
 *   args: ["-p", "console.log('hello')"],
 *   envs: { PATH: process.env.PATH },
 *   cwd: "/tmp"
 * });
 * console.log(`Exit code: ${result.exitCode}`);
 * console.log(`Path accesses:`, result.pathAccesses);
 * ```
 */
export declare function runCommand(options: RunCommandOptions): Promise<RunCommandResult>;

/**
 * Input parameters for running a command with fspy tracking.
 *
 * This structure contains the information needed to execute a command:
 * - `bin_name`: The name of the binary to execute
 * - `args`: Command line arguments to pass to the binary
 * - `envs`: Environment variables to set when executing the command
 * - `cwd`: The current working directory for the command
 */
export interface RunCommandOptions {
  /** The name of the binary to execute */
  binName: string;
  /** Command line arguments to pass to the binary */
  args: Array<string>;
  /** Environment variables to set when executing the command */
  envs: Record<string, string>;
  /** The current working directory for the command */
  cwd: string;
}

/**
 * Result returned by the run_command function.
 *
 * This structure contains:
 * - `exit_code`: The exit code of the command
 * - `path_accesses`: A map of relative paths to their access modes
 */
export interface RunCommandResult {
  /** The exit code of the command */
  exitCode: number;
  /** Map of relative paths to their access modes */
  pathAccesses: Record<string, PathAccess>;
}

/** Render the Vite+ header using the Rust implementation. */
export declare function vitePlusHeader(): string;
