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


try {
    $in=input_json(); $db=Database::connect();
    $user=(new PlayerAuthService($db))->authenticate($in);
    $account=(new WithdrawalAccountService($db))->bind(
        (int)$user['user_id'],
        (string)($in['method']??''),
        (string)($in['destination']??''),
        isset($in['account_name'])?(string)$in['account_name']:null
    );
    json_out(['ok'=>true,'account'=>$account],201);
} catch(Throwable $e) {
    json_out(['ok'=>false,'error'=>$e->getMessage()],422);
}
