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

// Path to sessions.json
$filePath = __DIR__ . '/../../database/login/sessions.json';

// Check if file exists
if (!file_exists($filePath)) {
    echo json_encode([
        "status" => "error",
        "message" => "Session file not found",
        "data" => []
    ]);
    exit;
}

// Read file contents
$content = file_get_contents($filePath);

// Decode JSON
$data = json_decode($content, true);

// Check for valid array
if (!is_array($data)) {
    echo json_encode([
        "status" => "error",
        "message" => "Invalid session file format",
        "data" => []
    ]);
    exit;
}

// Return success with session data
echo json_encode([
    "status" => "success",
    "count" => count($data),
    "data" => $data
]);
