<?php
// =============================================================================
// GET /has_playlist?mac=df:61:22:45:5d:1e — playlist existence check.
//
// Mapped from:  /check_playlist  (by Glass UrlRewriter)
//
// Returns plain text "0" or "1" — matches the IBO Ultra wire format byte-for-byte.
// =============================================================================

require_once __DIR__ . '/includes/client_common.php';

require_method('GET');

$mac = isset($_GET['mac']) ? (string)$_GET['mac'] : '';
$device = client_device_by_mac($mac);

$has = false;
if ($device) {
    $st = panel_db()->prepare('SELECT COUNT(*) FROM playlists WHERE device_id = ?');
    $st->execute([(int)$device['id']]);
    $has = ((int)$st->fetchColumn()) > 0;
}

$resp = $has ? '1' : '0';
client_log_request($device ? (int)$device['id'] : null,
                   'GET', '/has_playlist',
                   client_request_headers(), ['mac' => $mac], 200, $resp);
header('Content-Type: text/plain; charset=UTF-8');
header('Content-Length: ' . strlen($resp));
echo $resp;
