<?php
declare (strict_types = 1);

namespace app\listener\space;

use app\models\process\Boot;
use freedom\utils\SocketSession;
use think\swoole\WebSocket;

class ChangeBoot
{
    /**
     * 事件监听处理
     *
     * @return void
     */
    public function handle(array $event, WebSocket $ws)
    {
        $preliminaryCheckRes = SocketSession::preliminaryCheck($event,'space');
        if($preliminaryCheckRes['status'] == true){
            $tableInfo = $preliminaryCheckRes['data'];
            $modelRes = Boot::changeBoot($tableInfo);
            if ($modelRes['status'] == true){
                $ws->to(SocketSession::HOUSE_NAME)->emit('changeBoot',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $modelRes['data']]);
            }else{
                $ws->emit('changeBoot', ['status' => false, 'msg' => $modelRes['msg']]);
            }
        }else{
            $ws->emit('changeBoot', ['status' => false, 'msg' => $preliminaryCheckRes['msg']]);
        }
    }
}
