const db = require('../db');

async function createPaths34() {
    try {
        console.log('Creating Paths 3 & 4 structure...\n');

        // ===== PATH 3: SOC Analyst Level 1 =====
        console.log('PATH 3: SOC Analyst Level 1\n');

        const path3Modules = [
            { title: 'SIEM Fundamentals', tasks: 10 },
            { title: 'SIEM Use Cases', tasks: 10 },
            { title: 'EDR Concepts', tasks: 8 },
            { title: 'Intrusion Detection', tasks: 10 },
            { title: 'Malware Analysis Basics', tasks: 8 },
            { title: 'Incident Response Framework', tasks: 9 },
            { title: 'Digital Forensics Intro', tasks: 8 },
            { title: 'Network Traffic Analysis', tasks: 10 },
            { title: 'Threat Hunting Basics', tasks: 8 },
            { title: 'MITRE ATT&CK Framework', tasks: 10 },
            { title: 'Cloud Security Basics', tasks: 8 },
            { title: 'Security Automation', tasks: 7 },
            { title: 'Reporting & Documentation', tasks: 5 },
            { title: 'Capstone: SOC Simulation', tasks: 14 }
        ];

        for (const mod of path3Modules) {
            await db.query(
                'INSERT INTO modules (learning_path_id, title, description, estimated_hours) VALUES (?, ?, ?, ?)',
                [3, mod.title, `${mod.title} - comprehensive training`, 15]
            );
            const modId = (await db.query('SELECT LAST_INSERT_ID() as id')).rows[0].id;

            for (let i = 1; i <= mod.tasks; i++) {
                await db.query('INSERT INTO tasks (module_id, title, display_order, xp_reward) VALUES (?, ?, ?, ?)',
                    [modId, `${mod.title} - Task ${i}`, i, 40]);
            }
            console.log(`✓ ${mod.title} (${mod.tasks} tasks)`);
        }

        console.log('\n✅ Path 3 complete! (115 tasks)\n');

        // ===== PATH 4: Advanced SOC & Threat Hunting =====
        console.log('PATH 4: Advanced SOC & Threat Hunting\n');

        const path4Modules = [
            { title: 'Advanced SIEM', tasks: 10 },
            { title: 'Memory Forensics', tasks: 8 },
            { title: 'Malware Reverse Engineering', tasks: 8 },
            { title: 'Advanced Threat Intelligence', tasks: 9 },
            { title: 'Red vs Blue Team Dynamics', tasks: 7 },
            { title: 'Purple Teaming Exercises', tasks: 8 },
            { title: 'Container Security', tasks: 7 },
            { title: 'Zero Trust Architecture', tasks: 6 },
            { title: 'Compliance & Frameworks', tasks: 7 },
            { title: 'Career Development', tasks: 5 },
            { title: 'Certification Prep', tasks: 10 },
            { title: 'Final Capstone: APT Investigation', tasks: 10 }
        ];

        for (const mod of path4Modules) {
            await db.query(
                'INSERT INTO modules (learning_path_id, title, description, estimated_hours) VALUES (?, ?, ?, ?)',
                [4, mod.title, `${mod.title} - advanced training`, 15]
            );
            const modId = (await db.query('SELECT LAST_INSERT_ID() as id')).rows[0].id;

            for (let i = 1; i <= mod.tasks; i++) {
                await db.query('INSERT INTO tasks (module_id, title, display_order, xp_reward) VALUES (?, ?, ?, ?)',
                    [modId, `${mod.title} - Task ${i}`, i, 50]);
            }
            console.log(`✓ ${mod.title} (${mod.tasks} tasks)`);
        }

        console.log('\n✅ Path 4 complete! (95 tasks)\n');

        // Final count
        const counts = await db.query('SELECT COUNT(*) as count FROM tasks');
        const paths = await db.query('SELECT COUNT(*) as count FROM learning_paths');
        const modules = await db.query('SELECT COUNT(*) as count FROM modules');

        console.log('🎉 COMPLETE DATABASE STRUCTURE CREATED!\n');
        console.log('📊 Final Summary:');
        console.log(`   • Learning Paths: ${paths.rows[0].count}`);
        console.log(`   • Modules: ${modules.rows[0].count}`);
        console.log(`   • Tasks: ${counts.rows[0].count}`);

        process.exit(0);
    } catch (error) {
        console.error('Error:', error);
        process.exit(1);
    }
}

createPaths34();
