<?php
require __DIR__.'/_bootstrap.php';

use Zoo\Database;
use Zoo\Auth\PlayerAuthService;
use Zoo\Account\BindService;

try{
    $input=input_json();
    $db=Database::connect();
    $player=(new PlayerAuthService($db))->authenticate($input);
    $result=(new BindService($db))->requestPhoneCode(
        (int)$player['user_id'],
        (string)($input['phone'] ?? '')
    );
    json_out(['ok'=>true,'verification'=>$result],201);
}catch(Throwable $e){
    json_out(['ok'=>false,'error'=>$e->getMessage()],400);
}
