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

import android.text.TextUtils;

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

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * @author ZhuYongKang
 * @description 3D包点 和数 玩法
 * @date 2019/10/10
 */
public class BoxSum implements IBetBean {

    public List<BetNumber> mList;

    public BoxSum() {
        mList = new ArrayList<>();
    }

    @Override
    public void clear() {
        mList.clear();
    }

    @Override
    public boolean isFull() {
        return mList.size() == 1;
    }

    @Override
    public String toBetString() {
        StringBuilder builder = new StringBuilder();
        for (BetNumber number : mList) {
            builder.append(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 number = new BetNumber(StringTool.format2(Integer.parseInt(nums[0])));
            number.setType(BetNumber.CHECKED);
            mList.add(number);
        }
    }

    @Override
    public List<BetNumber> getAllNumberList() {
        return mList;
    }

    @Override
    public void random(int... args) {
        clear();
        //第一位
        Set<Integer> set1 = GameUtil.randomList(0, 27, 1);
        for (int i : set1) {
            BetNumber number = new BetNumber(StringTool.format2(i));
            number.setType(BetNumber.CHECKED);
            mList.add(number);
        }
    }

    public void add(BetNumber number) {
        BetNumber bet = new BetNumber(number.getNumber());
        bet.setType(number.getType());
        bet.setRed(number.isRed());
        mList.add(bet);
    }

    public void remove(BetNumber number) {
        for (BetNumber bet : mList) {
            if (bet.getNumber().equals(number.getNumber())) {
                mList.remove(bet);
                break;
            }
        }
    }

}
