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

async function forceResetRules() {
    logger.info('🔨 FORCING CLEAN RULE SET (ALL RULES POPULATED)...');

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

    if (!highRiskStart) return logger.error('❌ Profile not found');

    const newConfig = {
        execution: { allowedSymbols: ["BTC/USD"], orderType: "market" },
        riskLimits: { maxOpenTrades: 5, maxDailyLossUsd: 200 },
        rules: [
            { ruleId: "MomentumRule", enabled: true, params: { rsiPeriod: 14, overbought: 80, oversold: 20, timeframe: '15m' } },
            { ruleId: "EntryTriggerRule", enabled: true, params: { showPatterns: true } },
            { ruleId: "AIAnalysisRule", enabled: true, params: { minConfidence: 0.8 } },

            // Explicitly include disabled ones to ensure structure exists
            { ruleId: "TrendBiasRule", enabled: false, params: { fastPeriod: 50, slowPeriod: 200 } },
            { ruleId: "ZoneRule", enabled: false, params: { zonePercent: 1.5 } },
            { ruleId: "SessionRule", enabled: false, params: { sessions: "London,NY" } },
            { ruleId: "RiskManagementRule", enabled: true, params: { maxRisk: 5.0 } } // Also enabled
        ]
    };

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

    if (error) {
        logger.error(`❌ Failed: ${error.message}`);
    } else {
        logger.info(`✅ SUCCESS: Overwrote entire strategy_config for [${highRiskStart.name}]`);
        logger.info(`   - Includes 7 rules (4 Enabled, 3 Disabled)`);
        logger.info(`   - Includes default params for all`);
    }
}

forceResetRules();
