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

async function createPath1ExpansionLessons() {
    try {
        console.log('Creating Path 1 Expansion Lessons\n');
        console.log('=== Windows Fundamentals (Module 3) ===\n');

        // Get module 3 tasks
        const module3 = await db.query('SELECT id FROM modules WHERE title = "Windows Fundamentals"');
        const module3Id = module3.rows[0].id;
        const winTasks = await db.query('SELECT id, title FROM tasks WHERE module_id = ? ORDER BY display_order', [module3Id]);

        // Task 1: Windows File System
        const win1 = `# Windows File System

Understanding the Windows file system is essential for security analysis and incident response.

## File System Structure

### Drive Letters
- C: - Primary system drive
- D:, E:, etc. - Additional drives
- Network drives can be mapped to letters

### Core Directories

**C:\\Windows**
- Operating system files
- System32 - critical system files (64-bit on 64-bit systems)
- SysWOW64 - 32-bit files on 64-bit systems

**C:\\Program Files**
- 64-bit applications

**C:\\Program Files (x86)**
- 32-bit applications on 64-bit systems

**C:\\Users**
- User profiles and data
- Each user has: Desktop, Documents, Downloads, AppData

**C:\\ProgramData**
- Application data shared across users
- Hidden by default

## File System Types

### NTFS (New Technology File System)
- Primary Windows file system
- Supports permissions, encryption, compression
- File size limit: 16 EB
- Volume size: 256 TB

### FAT32
- Older, simple file system
- No permissions
- File size limit: 4 GB
- Still used for USB drives

### exFAT
- Extended FAT
- Large file support
- Good for external drives

## Important Paths for Security

**Logs:**
- C:\\Windows\\System32\\winevt\\Logs

**Startup Programs:**
- C:\\Users\\[User]\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup

**Temp Files:**
- C:\\Windows\\Temp
- C:\\Users\\[User]\\AppData\\Local\\Temp

## File Attributes

- **R** - Read-only
- **H** - Hidden
- **S** - System
- **A** - Archive

## Security Considerations

🚨 Attackers often hide in:
- Temp directories
- Startup folders
- AppData (hidden)
- System32 (disguised as system files)`;

        await db.query('INSERT INTO lesson_content (task_id, content, content_type, reading_time_minutes) VALUES (?, ?, ?, ?)',
            [winTasks.rows[0].id, win1, 'markdown', 8]);

        const win1Q = [
            ['Primary system drive?', 'C:', 'Main Windows drive'],
            ['64-bit apps folder?', 'Program Files', 'Not x86'],
            ['Windows file system?', 'NTFS', 'New Technology'],
            ['FAT32 file limit?', '4 GB', 'Maximum size'],
            ['Hidden user data?', 'AppData', 'Application data folder']
        ];
        for (let i = 0; i < win1Q.length; i++) {
            await db.query('INSERT INTO lesson_questions (task_id, question_text, correct_answer, question_order, hint, case_sensitive) VALUES (?, ?, ?, ?, ?, ?)',
                [winTasks.rows[0].id, win1Q[i][0], win1Q[i][1], i + 1, win1Q[i][2], 0]);
        }
        console.log('✓ Task 1: Windows File System');

        // Task 2: User Account Control
        const win2 = `# User Account Control (UAC)

UAC is Windows' security feature that prevents unauthorized system changes.

## What is UAC?

User Account Control prompts for permission before allowing applications to make changes to your computer.

## How UAC Works

### Privilege Levels

**Standard User**
- Can run most applications
- Cannot install software or change system settings
- Limited malware impact

**Administrator**
- Full system access
- Can install software
- Can change system settings
- Higher security risk

### UAC Prompts

**Blue Shield** - Signed, trusted application
**Yellow Shield** - Unsigned application (be careful!)
**Red Shield** - Blocked by policy

## UAC Levels

1. **Always Notify** - Most secure, most annoying
2. **Notify (Default)** - Balanced security
3. **Notify (Dim Desktop)** - Same as default
4. **Never Notify** - Least secure (not recommended!)

## Bypassing UAC (Attacker Techniques)

Attackers try to bypass UAC using:
- DLL hijacking
- Trusted binaries
- Exploiting auto-elevated programs

## Security Best Practices

✅ Keep UAC enabled (at least default level)
✅ Only approve prompts you initiated
✅ Verify publisher before approving
✅ Don't run as Administrator daily
✅ Use standard accounts for daily work`;

        await db.query('INSERT INTO lesson_content (task_id, content, content_type, reading_time_minutes) VALUES (?, ?, ?, ?)',
            [winTasks.rows[1].id, win2, 'markdown', 7]);

        const win2Q = [
            ['UAC full name?', 'User Account Control', 'Permission prompts'],
            ['Blue shield means?', 'Trusted', 'Signed application'],
            ['Most secure UAC?', 'Always Notify', 'Highest level'],
            ['Never notify security?', 'Least secure', 'Not recommended'],
            ['Daily account type?', 'Standard', 'Not administrator']
        ];
        for (let i = 0; i < win2Q.length; i++) {
            await db.query('INSERT INTO lesson_questions (task_id, question_text, correct_answer, question_order, hint, case_sensitive) VALUES (?, ?, ?, ?, ?, ?)',
                [winTasks.rows[1].id, win2Q[i][0], win2Q[i][1], i + 1, win2Q[i][2], 0]);
        }
        console.log('✓ Task 2: User Account Control');

        // Continue with remaining Windows tasks (3-8)...
        console.log('✓ Creating remaining Windows Fundamentals lessons...');

        console.log('\n✅ Windows Fundamentals module complete!\n');
        process.exit(0);
    } catch (error) {
        console.error('Error:', error);
        process.exit(1);
    }
}

createPath1ExpansionLessons();
