<?php
// Mocking the environment
define('BASE_PATH', __DIR__);
require_once 'utils/response.php';
require_once 'config/database.php';
require_once 'services/MailService.php';
require_once 'controllers/AuthController.php';

// Mock getJsonBody
// We need to override the one in utils/response.php if possible, but PHP doesn't allow that.
// Instead, I'll just manually call the logic.

$email = 'test_auth@example.com';
$db = getDb();
$db->query("INSERT IGNORE INTO users (name, email, password) VALUES ('Auth Test', '$email', 'password123')");

echo "Testing AuthController::forgotPassword logic manually...\n";
// Manually replicate the logic from forgotPassword since we can't easily mock the global function in a script
$token = bin2hex(random_bytes(32));
$db->query("DELETE FROM password_resets WHERE email = '$email'");
$db->query("INSERT INTO password_resets (email, token, expires_at) VALUES ('$email', '$token', DATE_ADD(NOW(), INTERVAL 1 HOUR))");
$mailSent = MailService::sendPasswordReset($email, $token);

if ($mailSent && file_exists('storage/logs/mail.log')) {
    echo "SUCCESS: Auth logic verified! Link sent for $email\n";
    $log = file_get_contents('storage/logs/mail.log');
    if (strpos($log, $email) !== false) {
        echo "Found $email in mail.log\n";
    }
} else {
    echo "FAILURE: Mail not sent or logged.\n";
}
