<?php
require __DIR__.'/_bootstrap.php';
use Zoo\Database;
use Zoo\Auth\PlayerAuthService;
use Zoo\Referral\ReferralService;
try{
    $in=input_json();$db=Database::connect();
    $p=(new PlayerAuthService($db))->authenticate($in);
    $r=(new ReferralService($db))->claim((int)$p['user_id']);
    json_out(['ok'=>true,'claim'=>$r]);
}catch(Throwable $e){json_out(['ok'=>false,'error'=>$e->getMessage()],422);}
