<?php

namespace App\Models;

class PcCaoHistory extends BaseModel
{
    protected $table = 'pc_cao_history';
    protected $fillable = ['date', 'total', 'big', 'small', 'odd', 'even', 'big_odd', 'big_even', 'small_odd',
        'small_even', 'max', 'min', 'pair', 'sequence', 'leopard',
        'num_0', 'num_1', 'num_2', 'num_3', 'num_4', 'num_5', 'num_6',
        'num_7', 'num_8', 'num_9', 'num_10', 'num_11', 'num_12', 'num_13',
        'num_14', 'num_15', 'num_16', 'num_17', 'num_18', 'num_19', 'num_20',
        'num_21', 'num_22', 'num_23', 'num_24', 'num_25', 'num_26', 'num_27',
    ];

    public static function updateData(array $awards)
    {
        $cao = static::where('date', date("Y-m-d"))->first();
        if (!$cao) $cao = static::create(['date' => date('Y-m-d')]);
        $cao->increment('total');
        if (in_array('大', $awards)) {
            $cao->increment('big');
        } else {
            $cao->increment('small');
        }
        if (in_array('单', $awards)) {
            $cao->increment('odd');
        } else {
            $cao->increment('even');
        }
        if (in_array('大单', $awards)) {
            $cao->increment('big_odd');
        }
        if (in_array('大双', $awards)) {
            $cao->increment('big_even');
        }
        if (in_array('小单', $awards)) {
            $cao->increment('small_odd');
        }
        if (in_array('小双', $awards)) {
            $cao->increment('small_even');
        }
        if (in_array('极大', $awards)) {
            $cao->increment('max');
        }
        if (in_array('极小', $awards)) {
            $cao->increment('min');
        }

        if (in_array('对子', $awards)) {
            $cao->increment('pair');
        }
        if (in_array('顺子', $awards)) {
            $cao->increment('sequence');
        }
        if (in_array('豹子', $awards)) {
            $cao->increment('leopard');
        }

        for ($i = 0; $i <= 27; $i++) {
            if (in_array("{$i}操", $awards)) {
                $cao->increment("num_{$i}");
                break;
            }
        }
    }
}