<?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);
    $binding=(new BindService($db))->claimInternalId(
        (int)$player['user_id'],
        (string)($input['login_id'] ?? ''),
        (string)($input['activation_code'] ?? '')
    );
    json_out(['ok'=>true,'binding'=>$binding]);
}catch(Throwable $e){
    json_out(['ok'=>false,'error'=>$e->getMessage()],400);
}
