<?php
require_once __DIR__ . '/../../connect.php';

$driver_id = filterRequest("driver_id");

// Driver invites count
$sqlDriver = "SELECT COUNT(*) as total FROM invites WHERE driverId = :driver_id AND isInstall = 1";
$stmtD = $con->prepare($sqlDriver);
$stmtD->bindParam(':driver_id', $driver_id, PDO::PARAM_INT);
$stmtD->execute();
$driverCount = $stmtD->fetchColumn();

// Passenger invites count
$sqlPass = "SELECT COUNT(*) as total FROM invitesToPassengers WHERE driverId = :driver_id AND isInstall = 1";
$stmtP = $con->prepare($sqlPass);
$stmtP->bindParam(':driver_id', $driver_id, PDO::PARAM_INT);
$stmtP->execute();
$passengerCount = $stmtP->fetchColumn();

// Rewards calculation (100 pts per driver, 50 pts per passenger)
$totalRewards = ($driverCount * 100) + ($passengerCount * 50);

jsonSuccess([
    [
        "driverInvites" => (int)$driverCount,
        "passengerInvites" => (int)$passengerCount,
        "totalRewards" => $totalRewards
    ]
]);
?>
