package com.genlot.ninglottery.game.d3.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 java.util.Set;

/**
 * @author ZhuYongKang
 * @description 3D单式投注实体类
 * @date 2019/8/26
 */
public class SingleD3 extends BetD3 {

    @Override
    public boolean isFull() {
        return mList1.size() == 1 && mList2.size() == 1 && mList3.size() == 1;
    }

    @Override
    public void random(int... args) {
        clear();
        //第一位
        Set<Integer> set1 = GameUtil.randomList(0, 9, 1);
        for (int i : set1) {
            BetNumber number = new BetNumber(String.valueOf(i));
            number.setType(BetNumber.CHECKED);
            mList1.add(number);
        }
        //第二位
        Set<Integer> set2 = GameUtil.randomList(0, 9, 1);
        for (int i : set2) {
            BetNumber number = new BetNumber(String.valueOf(i));
            number.setType(BetNumber.CHECKED);
            mList2.add(number);
        }
        //第二位
        Set<Integer> set3 = GameUtil.randomList(0, 9, 1);
        for (int i : set3) {
            BetNumber number = new BetNumber(String.valueOf(i));
            number.setType(BetNumber.CHECKED);
            mList3.add(number);
        }
    }

    /**
     * 1|2|3|
     * @return  String
     */
    @Override
    public String toBetString() {
        StringBuilder builder = new StringBuilder();
        for (BetNumber number : mList1) {
            builder.append(number.getNumber().equals("*") || number.getNumber().equals("-") ? "255" : number.getNumber());
        }
        builder.append("|");
        for (BetNumber number : mList2) {
            builder.append(number.getNumber().equals("*") || number.getNumber().equals("-") ? "255" : number.getNumber());
        }
        builder.append("|");
        for (BetNumber number : mList3) {
            builder.append(number.getNumber().equals("*") || number.getNumber().equals("-") ? "255" : number.getNumber());
        }
        builder.append("|");
        return builder.toString();
    }

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

    @Override
    public void add(BetNumber number, int index) {
        BetNumber bet = new BetNumber(number.getNumber());
        bet.setType(number.getType());
        bet.setRed(number.isRed());
        if (index == 0) {
            if (mList1.size() == 0) {
                mList1.add(bet);
            }
        } else if (index == 1) {
            if (mList2.size() == 0) {
                mList2.add(bet);
            }
        } else if (index == 2) {
            if (mList3.size() == 0) {
                mList3.add(bet);
            }
        }
    }

}
