import { logWarn } from '../utils';

/**
 * ConflictResolver: Analyzes agent actions for logical contradictions 
 * or goal conflicts (e.g., Security vs. Performance).
 */
export class ConflictResolver {
    /**
     * Analyzes proposed actions and returns a warning message if conflicts are found.
     */
    public static analyze(actions: any[]): string | null {
        if (!actions || actions.length === 0) return null;

        // 1. Resource Conflict: Multiple edits to sensitive core files
        const securityFiles = actions.filter(a => a.path && (a.path.includes('auth') || a.path.includes('security') || a.path.includes('config')));
        const performanceChanges = actions.filter(a => a.content && (a.content.includes('async') || a.content.includes('parallel') || a.content.includes('cache')));

        if (securityFiles.length > 0 && performanceChanges.length > 0) {
            return "Goal Conflict Detected: You are attempting to modify security-sensitive files while introducing performance optimizations (async/parallel). This might introduce race conditions or security vulnerabilities. Should I proceed with both, or prioritize Security?";
        }

        // 2. Structural Conflict: Modifying both interface and implementation in a way that might break contracts
        const interfaces = actions.filter(a => a.path && (a.path.endsWith('.d.ts') || a.path.includes('interface')));
        if (interfaces.length > 1 && actions.length > 10) {
            return "Structural Complexity Warning: This task involves massive changes to both interfaces and multiple implementations. This may lead to unexpected side effects. Would you like a step-by-step review?";
        }

        return null;
    }
}
