<?php
declare (strict_types = 1);

namespace app\listener\user;

use app\services\bet\ToBetBaccaratService;
use app\services\bet\ToBetDiceService;
use app\services\bet\ToBetRouletteService;
use app\services\bet\ToBetToningService;
use app\services\bet\ToBetDtService;
use app\services\bet\ToBetNnService;
use app\services\bet\ToBetTcService;
use freedom\utils\SocketSession;
use think\swoole\Websocket;

class ToBet
{
    /**
     * 事件监听处理
     *
     * @return void
     */
    public function handle(array $event, Websocket $ws)
    {
        $preliminaryCheckRes = SocketSession::preliminaryCheck($event,'user');
        $fd = $ws->getSender();
        if($preliminaryCheckRes['status'] == true){
            $tableInfo = $preliminaryCheckRes['data'];
            if(SocketSession::checkRepeat($fd,'user','isToBet')){
                switch ($tableInfo['game_id']){
                    case 1 :
                        ToBetBaccaratService::toBetBaccarat($event,$tableInfo);
                        break;
                    case 2 :
                        ToBetDtService::toBetDt($event,$tableInfo);
                        break;
                    case 4 :
                        ToBetNnService::toBetNn($event,$tableInfo);
                        break;
                    case 5 :
                        ToBetTcService::toBetTc($event,$tableInfo);
                        break;
                    case 6 :
                        ToBetToningService::toBetToning($event, $tableInfo);
                        break;
                    case 7 :
                        ToBetDiceService::toBetDice($event, $tableInfo);
                        break;
                    case 8 :
                        ToBetRouletteService::toBetRoulette($event, $tableInfo);
                        break;
                }
            }else{
                $ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'notice_repeat']);
            }
        }else{
            $ws->emit('changeBoot', ['status' => false, 'msg' => $preliminaryCheckRes['msg']]);
        }
    }
}
