
import { supabaseService } from '../src/services/SupabaseService.js';
import logger from '../src/utils/logger.js';
import { v4 as uuidv4 } from 'uuid';

async function createLowRiskProfile() {
    logger.info('🛡️ CREATING LOW RISK & SCALP PROFILES EXAMPLE...');

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

    // 2. Create "Low Risk Swing" Profile
    const lowRiskProfile = {
        user_id: user.user_id,
        name: "Low Risk Swing Trader 🛡️",
        allocated_capital: 2000,
        risk_per_trade_percent: 0.5, // Ultra Low Risk (0.5%)
        symbols: "BTC/USD,ETH/USD", // Major Pairs Only
        is_active: true,
        strategy_config: {
            riskLimits: {
                maxDailyLossUsd: 50, // Strict Stop
                maxOpenTrades: 2,
                maxConsecutiveLosses: 2
            },
            execution: { orderType: 'limit' }, // Limit Orders for safer entry
            rules: [
                { ruleId: 'TrendBiasRule', enabled: true },      // Must be with Trend (EMA200)
                { ruleId: 'ZoneRule', enabled: true },           // Must be near Support Zone
                { ruleId: 'RiskManagementRule', enabled: true }, // ATR Volatility Check
                { ruleId: 'SessionRule', enabled: true }         // Only London/NY Sessions
            ]
        }
    };

    // 3. Create "Aggressive Scalp" Profile (for contrast, if not exists)
    // We already renamed the first one to High Risk Scalper, so we just add the Low Risk one.

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

    if (error) {
        logger.error(`❌ Failed to create profile: ${error.message}`);
    } else {
        logger.info(`✅ Created Profile: [${lowRiskProfile.name}]`);
        logger.info(`   - Capital: $${lowRiskProfile.allocated_capital}`);
        logger.info(`   - Risk: ${lowRiskProfile.risk_per_trade_percent}% per trade`);
        logger.info(`   - Rules: Trend + Zone + RiskGuard + Session`);
        logger.info(`   - Strategy: Only trades major trend pullbacks during active sessions.`);
    }

    process.exit(0);
}

createLowRiskProfile().catch(console.error);
