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

import com.genlot.ninglottery.game.bet.BetNumber;
import com.genlot.ninglottery.model.PlayTypeID;

import java.util.List;
import java.util.Random;

/**
 * @author ZhuYongKang
 * @description 3D组选投注实体类
 * @date 2019/9/11
 */
public class ZuXuan extends SingleD3{

    /**
     *  不能三号相同
     * @param args int
     */
    @Override
    public void random(int... args) {
        clear();
        //第一位
        Random rand = new Random();
        int num1 = rand.nextInt(10);
        BetNumber number1 = new BetNumber(String.valueOf(num1));
        number1.setType(BetNumber.CHECKED);
        mList1.add(number1);
        //第二位
        int num2 = rand.nextInt(10);
        BetNumber number2 = new BetNumber(String.valueOf(num2));
        number2.setType(BetNumber.CHECKED);
        mList2.add(number2);
        //第三位
        int num3 = rand.nextInt(10);
        if (num1 == num2) {
            while (num3 == num1) {
                num3 = rand.nextInt(10);
            }
        }
        BetNumber number3 = new BetNumber(String.valueOf(num3));
        number3.setType(BetNumber.CHECKED);
        mList3.add(number3);
    }

    /**
     * 组选玩法每注的id
     * @param type type = 0 组选 type =1 包选
     * @return  int
     */
    public int getPlayTypeID(int type) {
        String num1 = mList1.get(0).getNumber();
        String num2 = mList2.get(0).getNumber();
        String num3 = mList3.get(0).getNumber();
        if (num1.equals(num2) || num1.equals(num3) || num2.equals(num3)) {
            return type == 0 ? PlayTypeID.D3_ZUSAN : PlayTypeID.D3_PACK3;
        } else {
            return type == 0 ? PlayTypeID.D3_ZULIU : PlayTypeID.D3_PACK6;
        }
    }

    public boolean contains(String number) {
        for (BetNumber betNumber : getAllNumberList()) {
            if (betNumber.getNumber().equals(number)) {
                return true;
            }
        }
        return false;
    }

    public boolean contains(List<BetNumber> list, String number) {
        for (BetNumber betNumber : list) {
            if (betNumber.getNumber().equals(number)) {
                return true;
            }
        }
        return false;
    }

}
