package com.genlot.ninglottery.game.ssq.bean;

import android.text.TextUtils;

import com.genlot.ninglottery.game.bet.BetNumber;
import com.genlot.ninglottery.game.ssq.SSQConfig;
import com.genlot.ninglottery.toolkit.GameUtil;
import com.genlot.ninglottery.toolkit.LogTool;
import com.genlot.ninglottery.toolkit.StringTool;

import java.util.Set;

/**
 * @author ZhuYongKang
 * @description 双色球复式投注实体类
 * @date 2019/8/28
 */
public class MultiSSQ extends BetSSQ {

    public void clearRed() {
        mRedList.clear();
    }

    public void clearBlue() {
        mBlueList.clear();
    }

    @Override
    public boolean isFull() {
        return mRedList.size() >= SSQConfig.MULTI_RED_MIN && mBlueList.size() >= SSQConfig.MULTI_BLUE_MIN &&
                (mRedList.size() + mBlueList.size()) >= SSQConfig.MULTI_TOTAL_MIN;
    }

    /**
     * 2|5|8|13|18|21|31|-9|13
     * @return  String
     */
    @Override
    public String toBetString() {
        StringBuilder builder = new StringBuilder();
        for (BetNumber number : mRedList) {
            builder.append(number.getNumber()).append("|");
        }
        builder.append("-");
        for (BetNumber number : mBlueList) {
            builder.append(number.getNumber()).append("|");
        }
        return builder.toString();
    }

    @Override
    public void parseBetData(String betData) {
        if (!TextUtils.isEmpty(betData)) {
            LogTool.logD("betData = " + betData);
            String[] nums = betData.split("-");
            String[] numsRed = nums[0].split("\\|");
            String[] numsBlue = nums[1].split("\\|");
            for (String red : numsRed) {
                BetNumber number = new BetNumber(StringTool.format2(Integer.parseInt(red)));
                number.setType(BetNumber.CHECKED);
                mRedList.add(number);
            }
            for (String blue : numsBlue) {
                BetNumber number = new BetNumber(StringTool.format2(Integer.parseInt(blue)));
                number.setType(BetNumber.CHECKED);
                number.setRed(false);
                mBlueList.add(number);
            }
        }
    }

    @Override
    public void random(int... args) {
        int red = args[0];
        int blue = args[1];
        clear();
        //红球
        Set<Integer> redSet = GameUtil.randomList(1, 33, red);
        for (int i : redSet) {
            BetNumber number = new BetNumber(StringTool.format2(i));
            number.setType(BetNumber.CHECKED);
            mRedList.add(number);
        }
        //蓝球
        Set<Integer> blueSet = GameUtil.randomList(1, 16, blue);
        for (int i : blueSet) {
            BetNumber number = new BetNumber(StringTool.format2(i));
            number.setType(BetNumber.CHECKED);
            number.setRed(false);
            mBlueList.add(number);
        }
    }

}
