<?php
// Cron job to process pending transactions and clean up old data
require_once __DIR__ . '/../includes/functions.php';

$functions = new InvestmentFunctions();

try {
    // NOTE: Auto-approval logic for deposits and withdrawals has been removed.
    // For a live environment, all pending transactions must be approved or rejected
    // manually from the admin panel (Admin -> Deposits / Admin -> Withdrawals).
    // For a fully automated system, you would integrate with a payment gateway's
    // Instant Payment Notification (IPN) or webhook to automatically verify and
    // complete transactions upon successful payment.

    // Clean up old login attempts (older than 30 days)
    $cleanup_stmt = $functions->db->prepare("DELETE FROM login_attempts WHERE attempt_time < DATE_SUB(NOW(), INTERVAL 30 DAY)");
    $cleanup_stmt->execute();
    $deleted_attempts = $cleanup_stmt->rowCount();

    // Clean up old activity logs (older than 90 days)
    $cleanup_stmt = $functions->db->prepare("DELETE FROM activity_logs WHERE created_at < DATE_SUB(NOW(), INTERVAL 90 DAY)");
    $cleanup_stmt->execute();
    $deleted_logs = $cleanup_stmt->rowCount();

    // Log summary
    if ($deleted_attempts > 0 || $deleted_logs > 0) {
        error_log("Process pending cron completed: Cleaned up $deleted_attempts login attempts and $deleted_logs activity logs.");
    }

} catch (Exception $e) {
    error_log("Cron job error in process-pending.php: " . $e->getMessage());
}
?>
