<?php

namespace freedom\utils;

class ToningUtil
{
    /**
     * 结果数目自增方法
     * @param $result
     * @param $afterCountString
     * @return int[]
     */
    public static function countInc($result, $afterCountString): array
    {
        $array = [
            'zero_count' => 0,
            'one_count' => 0,
            'two_count' => 0,
            'three_count' => 0,
            'four_count' => 0,
            'big_count' => 0,
            'small_count' => 0,
            'singular_count' => 0,
            'plural_count' => 0
        ];
        if ($result == 0){
            $array['zero_count'] = 1;
            $array['small_count'] = 1;
            $array['plural_count'] = 1;
        }
        if ($result == 1){
            $array['one_count'] = 1;
            $array['small_count'] = 1;
            $array['singular_count'] = 1;
        }
        if ($result == 2){
            $array['two_count'] = 1;
        }
        if ($result == 3){
            $array['three_count'] = 1;
            $array['big_count'] = 1;
            $array['singular_count'] = 1;
        }
        if ($result == 4){
            $array['four_count'] = 1;
            $array['big_count'] = 1;
            $array['plural_count'] = 1;
        }
        $afterCountArray = string_to_array($afterCountString);
        foreach ($array as $k => $v){
            foreach ($afterCountArray as $key => $value){
                if ($k == $key){
                    $array[$k] = $v + intval($value);
                }
            }
        }
        return $array;
    }

    /**
     * 下注额自增方法
     * @param $beforeAmountArray
     * @param $afterAmountArray
     * @return array
     */
    public static function amountInc($beforeAmountArray, $afterAmountArray): array
    {
        if (empty($beforeAmountArray)){
            $beforeAmountArray = [
                'toning_zero' => 0,
                'toning_four' => 0,
                'toning_one' => 0,
                'toning_three' => 0,
                'toning_big' => 0,
                'toning_small' => 0,
                'toning_singular' => 0,
                'toning_plural' => 0
            ];
        }
        $returnArray = [];
        foreach ($beforeAmountArray as $k => $v){
            foreach ($afterAmountArray as $key => $value){
                if ($k == $key){
                    $returnArray[$k] = intval($v) + intval($value);
                }
            }
        }
        return $returnArray;
    }

    /**
     * 结果汇总字符串转数组
     * @param $countString
     * @return array
     */
    public static function parseCount($countString): array
    {
        if (empty($countString)){
            return [
                'zero_count' => 0,
                'one_count' => 0,
                'two_count' => 0,
                'three_count' => 0,
                'four_count' => 0,
                'big_count' => 0,
                'small_count' => 0,
                'singular_count' => 0,
                'plural_count' => 0
            ];
        } else {
            return string_to_array($countString);
        }
    }
}
