/**
 * ServerValidator - Security validation for custom LSP servers
 *
 * @see spec.md US-004: Custom LSP Registration
 * @satisfies AC-US4-02, AC-US4-03, AC-US4-04
 */
/**
 * Validates custom LSP servers for security
 */
export class ServerValidator {
    constructor(trustStore, binaryChecker, warnCallback) {
        this.trustStore = trustStore;
        this.binaryChecker = binaryChecker;
        this.warnCallback = warnCallback;
    }
    /**
     * Validate a custom LSP server
     *
     * @param serverId - Unique identifier for the server
     * @param binaryPath - Path to the server binary
     * @returns Validation result
     */
    async validateCustomServer(serverId, binaryPath) {
        // Check if server is trusted
        const isTrusted = await this.trustStore.isTrusted(serverId);
        // Validate binary
        const binaryResult = await this.validateBinary(binaryPath);
        if (!binaryResult.valid) {
            return {
                valid: false,
                requiresConfirmation: false,
                error: binaryResult.error,
            };
        }
        // Show security warning for untrusted servers
        if (!isTrusted) {
            this.warnCallback(`⚠️ SECURITY WARNING: Custom LSP server "${serverId}" at "${binaryPath}" ` +
                'will be executed. Only use servers from trusted sources.');
            return {
                valid: true,
                requiresConfirmation: true,
            };
        }
        return {
            valid: true,
            requiresConfirmation: false,
        };
    }
    /**
     * Validate a binary file
     *
     * @param path - Path to the binary
     * @returns Validation result
     */
    async validateBinary(path) {
        const exists = await this.binaryChecker.exists(path);
        if (!exists) {
            return {
                valid: false,
                requiresConfirmation: false,
                error: `Binary not found: ${path}`,
            };
        }
        const isExecutable = await this.binaryChecker.isExecutable(path);
        if (!isExecutable) {
            return {
                valid: false,
                requiresConfirmation: false,
                error: `Binary not executable: ${path}`,
            };
        }
        return {
            valid: true,
            requiresConfirmation: false,
        };
    }
    /**
     * Confirm trust for a server
     *
     * @param serverId - Server ID to trust
     */
    async confirmTrust(serverId) {
        await this.trustStore.trust(serverId);
    }
}
//# sourceMappingURL=server-validator.js.map