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

import android.text.TextUtils;

import com.genlot.ninglottery.game.bet.BetNumber;
import com.genlot.ninglottery.toolkit.LogTool;

import java.util.Random;

/**
 * @author ZhuYongKang
 * @description 3D 1D投注实体类
 * @date 2019/10/14
 */
public class OneD extends SingleD3{

    @Override
    public void random(int... args) {
        clear();
        Random rand = new Random();
        int num = rand.nextInt(10);
        BetNumber number1 = new BetNumber(String.valueOf(num));
        number1.setType(BetNumber.CHECKED);
        BetNumber number3 = new BetNumber("-");
        number3.setType(BetNumber.CHECKED);
        BetNumber number2 = new BetNumber("-");
        number2.setType(BetNumber.CHECKED);
        //确定哪一位为数字
        int n = rand.nextInt(3);
        if (n == 0) {
            mList1.add(number1);
            mList2.add(number2);
            mList3.add(number3);
        } else if (n == 1) {
            mList2.add(number1);
            mList1.add(number2);
            mList3.add(number3);
        } else {
            mList3.add(number1);
            mList1.add(number2);
            mList2.add(number3);
        }
    }

    @Override
    public void parseBetData(String betData) {
        if (!TextUtils.isEmpty(betData)) {
            LogTool.logD("betData = " + betData);
            String[] nums = betData.split("\\|");
            BetNumber number1 = new BetNumber(nums[0].equals("255") ? "-" : nums[0]);
            number1.setType(BetNumber.CHECKED);
            mList1.add(number1);
            BetNumber number2 = new BetNumber(nums[1].equals("255") ? "-" : nums[1]);
            number2.setType(BetNumber.CHECKED);
            mList2.add(number2);
            BetNumber number3 = new BetNumber(nums[2].equals("255") ? "-" : nums[2]);
            number3.setType(BetNumber.CHECKED);
            mList3.add(number3);
        }
    }

    public int getLineNumber() {
        int num = 0;
        for (BetNumber number : getAllNumberList()) {
            if (number.getNumber().equals("-")) {
                num++;
            }
        }
        return num;
    }
}
