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

import com.genlot.ninglottery.game.bet.BetNumber;
import com.genlot.ninglottery.game.bet.IBetBean;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author ZhuYongKang
 * @description 双色球基类
 * @date 2019/9/3
 */
public abstract class BetSSQ implements IBetBean {

    public List<BetNumber> mRedList;
    public  List<BetNumber> mBlueList;
    public List<BetNumber> mDanList;

    public BetSSQ() {
        mRedList = new ArrayList<>();
        mBlueList = new ArrayList<>();
        mDanList = new ArrayList<>();
    }

    @Override
    public void clear() {
        mRedList.clear();
        mBlueList.clear();
        mDanList.clear();
    }

    @Override
    public List<BetNumber> getAllNumberList() {
        List<BetNumber> list = new ArrayList<>();
        list.addAll(mDanList);
        list.addAll(mRedList);
        list.addAll(mBlueList);
        return list;
    }

    public void add(BetNumber number) {
        BetNumber bet = new BetNumber(number.getNumber());
        bet.setType(number.getType());
        bet.setRed(number.isRed());
        if (number.isRed()) {
            if (number.getType() == BetNumber.DAN) {
                mDanList.add(bet);
                Collections.sort(mDanList, (o1, o2) -> Integer.parseInt(o1.getNumber()) - Integer.parseInt(o2.getNumber()));
            } else {
                mRedList.add(bet);
                Collections.sort(mRedList, (o1, o2) -> Integer.parseInt(o1.getNumber()) - Integer.parseInt(o2.getNumber()));
            }
        } else {
            mBlueList.add(bet);
            Collections.sort(mBlueList, (o1, o2) -> Integer.parseInt(o1.getNumber()) - Integer.parseInt(o2.getNumber()));
        }
    }

    public void remove(BetNumber number) {
        if (number.isRed()) {
            if (number.getType() == BetNumber.DAN) {
                for (BetNumber betNumber : mDanList) {
                    if (betNumber.getNumber().equals(number.getNumber())) {
                        mDanList.remove(betNumber);
                        break;
                    }
                }
            } else {
                for (BetNumber betNumber : mRedList) {
                    if (betNumber.getNumber().equals(number.getNumber())) {
                        mRedList.remove(betNumber);
                        break;
                    }
                }
            }
        } else {
            for (BetNumber betNumber : mBlueList) {
                if (betNumber.getNumber().equals(number.getNumber())) {
                    mBlueList.remove(betNumber);
                    break;
                }
            }
        }
    }

}
