<?php
declare(strict_types=1);

require_once __DIR__ . '/../includes/bootstrap.php';

echo "Updating admin email...\n\n";

try {
    $pdo = Database::pdo();
    
    $stmt = $pdo->prepare("UPDATE users SET email = 'admin@spm.com' WHERE email = 'admin@pestcontrol.com' AND user_type = 'admin'");
    $stmt->execute();
    
    $rowsAffected = $stmt->rowCount();
    
    if ($rowsAffected > 0) {
        echo "✓ Admin email updated successfully!\n";
        echo "  Changed from: admin@pestcontrol.com\n";
        echo "  Changed to: admin@spm.com\n";
        echo "  Rows affected: $rowsAffected\n\n";
    } else {
        echo "⚠ No admin user found with email admin@pestcontrol.com\n";
        echo "  Checking current admin emails...\n\n";
        
        $stmt = $pdo->query("SELECT user_id, email, full_name FROM users WHERE user_type = 'admin'");
        $admins = $stmt->fetchAll();
        
        if ($admins) {
            echo "  Current admin users:\n";
            foreach ($admins as $admin) {
                echo "  - ID: {$admin['user_id']}, Email: {$admin['email']}, Name: {$admin['full_name']}\n";
            }
        } else {
            echo "  No admin users found in database.\n";
        }
    }
    
} catch (Throwable $e) {
    echo "✗ Error: " . $e->getMessage() . "\n";
    exit(1);
}
