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

async function createAggressiveProfile() {
    logger.info('🚀 CREATING AGGRESSIVE TEST PROFILE (70% VOTING)...');

    // 1. Get User
    const users = await supabaseService.getActiveUsers();
    if (users.length === 0) {
        logger.error('❌ No active users found.');
        return;
    }
    const user = users[0];

    // 2. Prepare Profile
    const aggressiveProfile = {
        user_id: user.user_id,
        name: "Aggressive Test (70% Voting)",
        allocated_capital: 5000,
        symbols: "BTC/USDT,ETH/USDT,SOL/USDT",
        is_active: false,
        strategy_config: {
            rules: [
                { ruleId: 'TrendBiasRule', enabled: true, params: { emaFast: 50, emaSlow: 200 } },
                { ruleId: 'SessionRule', enabled: true, params: { allowedSessions: ['NY', 'LDN'] } },
                { ruleId: 'ZoneRule', enabled: true, params: { emaPeriod: 20 } },
                { ruleId: 'MomentumRule', enabled: true, params: { rsiPeriod: 14 } },
                { ruleId: 'EntryTriggerRule', enabled: true, params: {} },
                { ruleId: 'RiskManagementRule', enabled: true, params: { atrPeriod: 14 } },
                { ruleId: 'AIAnalysisRule', enabled: false, params: { minConfidence: 80 } }
            ],
            riskLimits: {
                maxDailyLossUsd: 50,
                dailyProfitTargetUsd: 100,
                maxOpenTrades: 2,
                maxConsecutiveLosses: 2
            },
            execution: {
                orderType: 'market',
                cooldownMinutes: 30,
                minRulePassRatio: 0.7,
                entryMode: 'both'
            }
        }
    };

    // 3. Insert Profile
    // @ts-ignore
    const { data, error } = await supabaseService.client
        .from('trade_profiles')
        .insert([aggressiveProfile])
        .select()
        .single();

    if (error) {
        logger.error(`❌ Failed to create profile: ${error.message}`);
    } else {
        logger.info(`✅ Created Profile: [${aggressiveProfile.name}]`);
        logger.info(`   - Capital: $${aggressiveProfile.allocated_capital}`);
        logger.info(`   - Rules: 4 Voting (70%), 2 Mandatory, AI Disabled`);
        logger.info(`   - Target: $100 Profit Target | $50 Daily Loss Max`);
    }

    process.exit(0);
}

createAggressiveProfile().catch(console.error);
