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

use Zoo\Database;
use Zoo\Auth\PlayerAuthService;
use Zoo\Reward\VipMinuteGiftService;

try{
    $db=Database::connect();
    $player=(new PlayerAuthService($db))->authenticate(input_json());
    $uid=(int)$player['user_id'];

    $svc=new VipMinuteGiftService($db);
    $result=$svc->claim($uid);

    json_out([
      'ok'=>true,
      'result'=>$result,
      'status'=>$svc->status($uid),
      'recent_minutes'=>$svc->recentMinutes($uid,20)
    ]);
}catch(Throwable $e){
    json_out(['ok'=>false,'error'=>$e->getMessage()],422);
}
