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

$data = json_decode(file_get_contents("php://input"));
$google_id = isset($data->google_id) ? $data->google_id : null;

if (!$google_id) {
    echo json_encode(["success" => false]);
    exit;
}

$stmt = $conn->prepare("SELECT credits FROM users WHERE google_id = ?");
$stmt->bind_param("s", $google_id);
$stmt->execute();
$stmt->bind_result($credits);

if ($stmt->fetch()) {
    echo json_encode(["success" => true, "credits" => $credits]);
} else {
    echo json_encode(["success" => false]);
}

$stmt->close();
$conn->close();
?>
