<?php
require __DIR__ . '/../lib/bootstrap.php';
handle_cors_preflight();

$device = get_or_create_device($_GET['mac'] ?? '');
$playlists = get_device_playlists((int) $device['id']);
$playlist = get_device_playlist((int) $device['id']);

json_response([
    'ok' => true,
    'mac' => $device['mac'],
    'status' => $device['status'],
    'trial_started_at' => $device['trial_started_at'],
    'trial_ends_at' => $device['trial_ends_at'],
    'active_until' => $device['active_until'],
    'access' => device_access($device),
    'playlist' => public_playlist_payload($playlist),
    'playlists' => public_playlists_payload($playlists),
]);
