<?php
require_once("config.php");

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

if (!isset($_GET['hwid'])) {
    echo json_encode(['error' => 'Missing HWID parameter']);
    exit;
}

$hwid = mysqli_real_escape_string($condb, $_GET['hwid']);

// Check if favorites table exists, if not create it
$createTable = "CREATE TABLE IF NOT EXISTS favorites (
    hwid VARCHAR(255) PRIMARY KEY,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
mysqli_query($condb, $createTable);

// Check if the bot is marked as favorite
$query = "SELECT hwid FROM favorites WHERE hwid = ?";
$stmt = mysqli_prepare($condb, $query);
mysqli_stmt_bind_param($stmt, "s", $hwid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);

echo json_encode([
    'success' => true,
    'is_favorite' => mysqli_num_rows($result) > 0
]); 