<?php
require __DIR__.'/_bootstrap.php';
use Zoo\Database;
use Zoo\Auth\PlayerAuthService;
use Zoo\Deposit\DepositService;

try{
    $in=input_json();
    $db=Database::connect();
    $player=(new PlayerAuthService($db))->authenticate($in);
    $d=(new DepositService($db))->submitReference(
        (int)$player['user_id'],
        (int)($in['deposit_id']??0),
        (string)($in['payer_reference']??'')
    );
    json_out(['ok'=>true,'deposit'=>$d]);
}catch(Throwable $e){
    json_out(['ok'=>false,'error'=>$e->getMessage()],422);
}
