package com.genlot.ninglottery.game.qlc.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/11
 */
public abstract class Bet7lc implements IBetBean {

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

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

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

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

    public void add(BetNumber number) {
        BetNumber bet = new BetNumber(number.getNumber());
        bet.setType(number.getType());
        bet.setRed(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()));
        }
    }

    public void remove(BetNumber number) {
        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;
                }
            }
        }
    }

}
