<?php
session_start();
require_once '../connection.php';

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

if (!isset($_SESSION['admin_id'])) {
    echo json_encode(['success' => false, 'message' => 'Unauthorized']);
    exit();
}

$session_id = intval($_GET['id'] ?? 0);

if (!$session_id) {
    echo json_encode(['success' => false, 'message' => 'Invalid session ID']);
    exit();
}

$query = "
    SELECT 
        ms.*,
        u.username,
        u.full_name,
        u.email
    FROM mining_sessions ms
    JOIN users u ON ms.user_id = u.id
    WHERE ms.id = ?
";

$stmt = $conn->prepare($query);
$stmt->bind_param("i", $session_id);
$stmt->execute();
$result = $stmt->get_result();

if ($row = $result->fetch_assoc()) {
    echo json_encode(['success' => true, 'session' => $row]);
} else {
    echo json_encode(['success' => false, 'message' => 'Session not found']);
}

$stmt->close();
?>