<?php
require __DIR__.'/_bootstrap.php';
use Zoo\Database;
use Zoo\Auth\PlayerAuthService;
use Zoo\Referral\ReferralService;
try{
    $db=Database::connect();
    $p=(new PlayerAuthService($db))->authenticate([]);
    $r=(new ReferralService($db))->downline(
        (int)$p['user_id'],
        (string)($_GET['search']??''),
        (int)($_GET['level']??0),
        (int)($_GET['page']??1),
        (int)($_GET['limit']??20)
    );
    json_out(['ok'=>true,'downline'=>$r]);
}catch(Throwable $e){json_out(['ok'=>false,'error'=>$e->getMessage()],422);}
