<?php
$tenant = $_POST['tenant'] ?? '';
if ($tenant !== '' && file_exists('../../../' . $tenant . '/config.php')) {
    require_once('../../../' . $tenant . '/config.php');
}
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

header('Content-Type: application/json');

$mode = $_POST['mode'] ?? '';
if ($mode !== 'keepalive') {
    http_response_code(400);
    echo json_encode(['status' => 'error', 'message' => 'Invalid PNA process mode']);
    exit;
}

$_SESSION['mass_pna_keepalive'] = time();
$_SESSION['mass_pna_last_total'] = (int) ($_POST['total'] ?? 0);
$_SESSION['mass_pna_last_processed'] = (int) ($_POST['processed'] ?? 0);

session_write_close();

echo json_encode(['status' => 'ok', 'time' => time()]);
