<?php
header("Content-Type: application/json");
header("Access-Control-Allow-Origin: *");

// Include database configuration
require_once 'config.php';  // Update with your DB configuration path

$conn = getDbConnection();

// Fetch the latest user_id and increment by 1
$sql = "SELECT MAX(user_id) + 1 AS next_user_id FROM users";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    $row = $result->fetch_assoc();
    echo json_encode(array("next_user_id" => $row['next_user_id'] ?? 1));  // Defaults to 1 if no users
} else {
    echo json_encode(array("next_user_id" => 1));
}

$conn->close();
?>

