<?php
require __DIR__.'/_bootstrap.php';
use Zoo\Database;
use Zoo\Admin\AdminApiAuth;
use Zoo\Admin\WithdrawalAdminService;

try {
    AdminApiAuth::requireKey();
    $in=input_json();
    $r=(new WithdrawalAdminService(Database::connect()))->action(
        (int)($in['withdrawal_id']??0),
        (string)($in['action']??''),
        isset($in['note'])?(string)$in['note']:null,
        isset($in['txid'])?(string)$in['txid']:null
    );
    json_out(['ok'=>true,'withdrawal'=>$r]);
} catch(Throwable $e) {
    json_out(['ok'=>false,'error'=>$e->getMessage()],422);
}
