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

import android.text.TextUtils;

import com.genlot.ninglottery.game.bet.BetNumber;
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/26
 */
public class SingleSSQ extends BetSSQ {


    @Override
    public boolean isFull() {
        return mRedList.size() == 6 && mBlueList.size() == 1;
    }

    /**
     * 1|2|3|4|5|6|-16|
     * @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();
    }

    /**
     * 解析投注号码
     * @param betData 1|2|3|4|5|6|-16|-
     */
    @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) {
        clear();
        //红球
        Set<Integer> redSet = GameUtil.randomList(1, 33, 6);
        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, 1);
        for (int i : blueSet) {
            BetNumber number = new BetNumber(StringTool.format2(i));
            number.setType(BetNumber.CHECKED);
            number.setRed(false);
            mBlueList.add(number);
        }
    }


}
