
import { supabaseService } from '../src/services/SupabaseService.js';
import logger from '../src/utils/logger.js';

async function fixHighRiskRules() {
    logger.info('🔧 Syncing High Risk Rules with Dashboard UI...');

    const profiles = await supabaseService.getActiveProfiles();
    const highRiskProfile = profiles.find(p => p.name.includes('Scalp'));

    if (!highRiskProfile) {
        logger.error('❌ High Risk Profile not found.');
        return;
    }

    // Update with Dashboard-compatible Rule IDs
    const newRules = [
        { ruleId: 'MomentumRule', enabled: true },      // Aggressive Momentum (RSI)
        { ruleId: 'EntryTriggerRule', enabled: true },  // Pattern Trigger
        { ruleId: 'AIAnalysisRule', enabled: true }     // AI Confirmation
    ];

    // @ts-ignore
    const { error } = await supabaseService.client
        .from('trade_profiles')
        .update({
            strategy_config: {
                ...highRiskProfile.strategy_config,
                rules: newRules
            }
        })
        .eq('id', highRiskProfile.id);

    if (error) {
        logger.error(`❌ Failed: ${error.message}`);
    } else {
        logger.info(`✅ Rules Updated for [${highRiskProfile.name}]`);
        logger.info(`   - MomentumRule: ON`);
        logger.info(`   - EntryTriggerRule: ON`);
        logger.info(`   - AIAnalysisRule: ON`);
        logger.info(`   (Refresh Dashboard to see them selected)`);
    }
}

fixHighRiskRules();
