<?php
declare (strict_types = 1);

namespace app\listener\space;

use app\models\process\Sumday;
use freedom\utils\SocketSession;
use think\swoole\Websocket;

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