/**
 * Base Native Provider
 *
 * Abstract base class for platform-native desktop automation providers.
 * Provides shared utilities for executing CLI tools, checking tool availability,
 * and common helper methods.
 */
import { execSync, exec as execCb } from 'child_process';
import { promisify } from 'util';
const execAsync = promisify(execCb);
export class BaseNativeProvider {
    name = 'native';
    initialized = false;
    availableTools = new Map();
    /**
     * Execute a command asynchronously with optional timeout
     */
    async exec(cmd, timeout = 10000) {
        const { stdout } = await execAsync(cmd, {
            timeout,
            encoding: 'utf-8',
            maxBuffer: 1024 * 1024,
        });
        return stdout.trim();
    }
    /**
     * Execute a command synchronously
     */
    execSync(cmd, timeout = 5000) {
        return execSync(cmd, {
            encoding: 'utf-8',
            timeout,
            maxBuffer: 1024 * 1024,
        }).trim();
    }
    /**
     * Check if a CLI tool is available (cached)
     */
    checkTool(name) {
        if (this.availableTools.has(name)) {
            return this.availableTools.get(name);
        }
        let available = false;
        try {
            execSync(`which ${name}`, { encoding: 'utf-8', timeout: 3000 });
            available = true;
        }
        catch {
            available = false;
        }
        this.availableTools.set(name, available);
        return available;
    }
    /**
     * Check if a tool is available (from cache)
     */
    hasTool(name) {
        return this.availableTools.get(name) ?? false;
    }
    /**
     * Delay helper
     */
    delay(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
    }
    /**
     * Ensure provider is initialized
     */
    ensureInitialized() {
        if (!this.initialized) {
            throw new Error(`${this.platformName} native provider not initialized. Call initialize() first.`);
        }
    }
}
//# sourceMappingURL=base-native-provider.js.map