<?php
require __DIR__.'/_bootstrap.php';
use Zoo\Database;
use Zoo\Auth\GuestService;
use Zoo\Wallet\WalletQuery;

try {
    $db=Database::connect();
    $guest=(new GuestService($db))->createGuest(
        $_SERVER['HTTP_USER_AGENT'] ?? null,
        $_SERVER['REMOTE_ADDR'] ?? null
    );
    $wallet=(new WalletQuery($db))->get((int)$guest['user_id']);
    json_out(['ok'=>true,'guest'=>$guest,'wallet'=>$wallet],201);
} catch(Throwable $e) {
    json_out(['ok'=>false,'error'=>$e->getMessage()],500);
}
