<?php
declare(strict_types=1);

/**
 * /public_html/test_erp/api/auth/ping_session.php
 * Session Status / Keep-alive Endpoint — TEST Environment
 */

require_once __DIR__ . '/../../config/session.php';

header('Content-Type: application/json; charset=UTF-8');
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');

$loggedIn = function_exists('is_logged_in')
    ? is_logged_in()
    : (
        isset($_SESSION['user_id'])
        && (int) $_SESSION['user_id'] > 0
    );

/*
|--------------------------------------------------------------------------
| Active login থাকলে activity time refresh
|--------------------------------------------------------------------------
*/

if ($loggedIn) {
    $_SESSION['LAST_ACTIVITY'] = time();
}

http_response_code(200);

echo json_encode([
    'status'    => true,
    'success'   => true,
    'ok'        => true,
    'code'      => 200,
    'logged_in' => $loggedIn,
    'message'   => $loggedIn
        ? 'Session active'
        : 'Session inactive',
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);

exit;