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

$name = $_GET['name'] ?? '';

if ($name === '') {
    echo json_encode(['valid' => false]);
    exit;
}

$stmt = $pdo->prepare(
    "SELECT 1 FROM departments WHERE BINARY name = BINARY :name LIMIT 1"
);
$stmt->execute([':name' => $name]);

echo json_encode([
    'valid' => $stmt->fetchColumn() !== false
]);