<?php


namespace app\services\connect;


use app\models\process\Boot;
use app\models\process\NumberTab;
use app\models\process\Sumday;

/**
 * TODO 桌子状态服务
 * Class InitTableService
 * @package app\services\connect
 */
class InitTableService
{
    /**
     * TODO 控制台登录处理
     * @param array $tableInfo
     * @return array
     */
    public static function initTable(array $tableInfo): array
    {
        //查询日结
        $lastSumday = Sumday::getByTableIdOrderByIdDesc($tableInfo);
        if (!$lastSumday) $lastSumday = Sumday::addByTable($tableInfo);
        //查询靴
        $lastBoot = Boot::getByTableIdOrderByIdDesc($tableInfo);
        if (!$lastBoot) $lastBoot = Boot::addBySumday($lastSumday);
        //查询铺
        $lastNumberTab = NumberTab::getByBootIdOrderByIdDesc($lastBoot);
        if (!$lastNumberTab) $lastNumberTab = NumberTab::addByBoot($lastBoot);
        return $lastNumberTab;
    }

    /**
     * TODO 桌子状态获取
     * @param array $numberTabInfo
     * @return array
     */
    public static function numberTabStatus(array $numberTabInfo): array{
        switch ($numberTabInfo['bet_status']){
            case 1:
                $return = ['bet_status' => 1, 'bet_msg' => 'bet_status_1'];
                break;
            case 2:
                $return = ['bet_status' => 2, 'bet_msg' => 'bet_status_2'];
                break;
            default:
                $return = ['bet_status' => 0, 'bet_msg' => 'bet_status_0'];
                break;
        }
        switch ($numberTabInfo['rob_status']){
            case 1:
                $return = array_merge(['rob_status' => 1, 'bet_msg' => 'rob_status_1'],$return);
                break;
            case 2:
                $return = array_merge(['rob_status' => 2, 'bet_msg' => 'rob_status_2'],$return);
                break;
            default:
                $return = array_merge(['rob_status' => 0, 'bet_msg' => 'rob_status_0'],$return);
                break;
        }
        return $return;
    }
}