package com.genlot.ninglottery.game.k3.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 类描述
 * @date 2019/10/21
 */
public class SumK3 implements IBetBean {

    public List<BetNumber> mList;

    public SumK3() {
        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(4, 17, 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());
        mList.add(bet);
    }

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

}
