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

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