<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'includes/config.php';

echo "Config OK<br>";

try {
    require_once 'includes/commission.php';
    echo "Commission OK<br>";
} catch(Exception $e) {
    echo "Commission Error: " . $e->getMessage() . "<br>";
}

$db = getDB();
echo "DB OK<br>";

try {
    $db->exec("CREATE TABLE IF NOT EXISTS drive_requests (
        id INT AUTO_INCREMENT PRIMARY KEY,
        user_id INT NOT NULL,
        package_id INT,
        phone_number VARCHAR(20),
        amount DECIMAL(10,2),
        commission_percent DECIMAL(5,2) DEFAULT 0,
        commission_amount DECIMAL(10,2) DEFAULT 0,
        balance_before DECIMAL(10,2),
        balance_after DECIMAL(10,2),
        reference VARCHAR(50),
        status ENUM('pending','processing','success','failed') DEFAULT 'pending',
        note TEXT,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
    )");
    echo "drive_requests table OK<br>";
} catch(Exception $e) {
    echo "Table error: " . $e->getMessage() . "<br>";
}

try {
    $pkgs = $db->query("SELECT COUNT(*) FROM drive_packages")->fetchColumn();
    echo "drive_packages count: $pkgs<br>";
} catch(Exception $e) {
    echo "drive_packages error: " . $e->getMessage() . "<br>";
}

try {
    requireLogin();
    echo "Login OK<br>";
} catch(Exception $e) {
    echo "Login error<br>";
}

echo "All OK - drive.php should work";
