<?php
declare (strict_types = 1);

namespace app\listener\scan;

use app\models\table\Table;
use app\services\scan\ScanTcService;
use freedom\utils\SocketSession;
use think\swoole\Websocket;

class Tc
{
    /**
     * 事件监听处理
     *
     * @return void
     */
    public function handle(array $event, Websocket $ws)
    {
        if (!isset($event['table_id']) || empty(intval($event['table_id']))){
            $ws->emit('sendScanResult',['status' => false, 'msg' => "not_table_data"]);
        }
        $tableInfo = Table::get(intval($event['table_id']));
        $serviceRes = ScanTcService::doScanTc($event,$tableInfo);
        if ($serviceRes['status']){
            $ws->to(SocketSession::HOUSE_NAME)->emit('sendScanResult',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $serviceRes['data']]);
        }else{
            $ws->emit('sendScanResult',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => $serviceRes['msg']]);
        }
    }
}
