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

$license_key = trim($_POST['license_key'] ?? '');

if ($license_key === '') {
    echo json_encode(['success' => false, 'message' => 'License key is required.']);
    exit;
}

// Check if already exists
$check = $conn->query("SELECT id FROM branch_info LIMIT 1");
if ($check->num_rows > 0) {
    $stmt = $conn->prepare("UPDATE branch_info SET license_key = ? WHERE id = 1");
    $stmt->bind_param("s", $license_key);
    $stmt->execute();
} else {
    $stmt = $conn->prepare("INSERT INTO branch_info (license_key) VALUES (?)");
    $stmt->bind_param("s", $license_key);
    $stmt->execute();
}

echo json_encode(['success' => true, 'message' => 'License key saved.']);
?>
