/**
 * CLI Plugin Types
 *
 * Type definitions for the CLI plugin system.
 * Plugins can register commands and aliases to extend the CLI.
 */
// ============================================================================
// Type Guards
// ============================================================================
/**
 * Validates that an object is a valid CLIPlugin
 */
export function isValidCLIPlugin(obj) {
    if (typeof obj !== 'object' || obj === null) {
        return false;
    }
    const plugin = obj;
    // Required fields
    if (typeof plugin.name !== 'string' || plugin.name.length === 0) {
        return false;
    }
    if (typeof plugin.version !== 'string' || plugin.version.length === 0) {
        return false;
    }
    if (!Array.isArray(plugin.commands)) {
        return false;
    }
    // Validate commands array
    for (const cmd of plugin.commands) {
        if (!isValidCommand(cmd)) {
            return false;
        }
    }
    // Optional aliases
    if (plugin.aliases !== undefined) {
        if (typeof plugin.aliases !== 'object' || plugin.aliases === null) {
            return false;
        }
        for (const [key, value] of Object.entries(plugin.aliases)) {
            if (typeof key !== 'string' || typeof value !== 'string') {
                return false;
            }
        }
    }
    // Optional init function
    if (plugin.init !== undefined && typeof plugin.init !== 'function') {
        return false;
    }
    return true;
}
/**
 * Validates that an object is a valid Command
 */
function isValidCommand(obj) {
    if (typeof obj !== 'object' || obj === null) {
        return false;
    }
    const cmd = obj;
    // Required fields
    if (typeof cmd.name !== 'string' || cmd.name.length === 0) {
        return false;
    }
    if (typeof cmd.description !== 'string') {
        return false;
    }
    if (typeof cmd.usage !== 'string') {
        return false;
    }
    if (typeof cmd.handler !== 'function') {
        return false;
    }
    // Optional subcommands
    if (cmd.subcommands !== undefined) {
        if (typeof cmd.subcommands !== 'object' || cmd.subcommands === null) {
            return false;
        }
        for (const subCmd of Object.values(cmd.subcommands)) {
            if (!isValidCommand(subCmd)) {
                return false;
            }
        }
    }
    return true;
}
/**
 * Validates plugin configuration
 */
export function isValidPluginsConfig(obj) {
    if (typeof obj !== 'object' || obj === null) {
        return false;
    }
    const config = obj;
    if (!Array.isArray(config.packages)) {
        return false;
    }
    for (const pkg of config.packages) {
        if (typeof pkg !== 'string' || pkg.length === 0) {
            return false;
        }
    }
    return true;
}
//# sourceMappingURL=plugin-types.js.map