<?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))->create(
        (int)$player['user_id'],
        (float)($in['amount']??0),
        (string)($in['method']??'')
    );
    json_out(['ok'=>true,'deposit'=>$d],201);
}catch(Throwable $e){
    json_out(['ok'=>false,'error'=>$e->getMessage()],422);
}
