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

import android.text.TextUtils;

import com.genlot.ninglottery.game.bet.BetNumber;
import com.genlot.ninglottery.toolkit.LogTool;

import java.util.Collections;

/**
 * @author ZhuYongKang
 * @description 直选复式投注类
 * @date 2019/10/15
 */
public class MultiD3 extends BetD3{

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

    @Override
    public String toBetString() {
        StringBuilder builder = new StringBuilder();
        for (BetNumber number : mList1) {
            builder.append(number.getNumber()).append("|");
        }
        builder.append("-");
        for (BetNumber number : mList2) {
            builder.append(number.getNumber()).append("|");
        }
        builder.append("-");
        for (BetNumber number : mList3) {
            builder.append(number.getNumber()).append("|");
        }
        return builder.toString();
    }

    @Override
    public void parseBetData(String betData) {
        if (!TextUtils.isEmpty(betData)) {
            LogTool.logD("betData = " + betData);
            String[] nums = betData.split("-");
            String[] numsBai = nums[0].split("\\|");
            String[] numsShi = nums[1].split("\\|");
            String[] numsGe = nums[2].split("\\|");
            for (String bai : numsBai) {
                BetNumber number = new BetNumber(String.valueOf(bai));
                number.setType(BetNumber.CHECKED);
                mList1.add(number);
            }
            for (String shi : numsShi) {
                BetNumber number = new BetNumber(String.valueOf(shi));
                number.setType(BetNumber.CHECKED);
                mList2.add(number);
            }
            for (String ge : numsGe) {
                BetNumber number = new BetNumber(String.valueOf(ge));
                number.setType(BetNumber.CHECKED);
                mList3.add(number);
            }
        }
    }

    @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) {
            mList1.add(bet);
            Collections.sort(mList1, (o1, o2) -> Integer.parseInt(o1.getNumber()) - Integer.parseInt(o2.getNumber()));
        } else if (index == 1) {
            mList2.add(bet);
            Collections.sort(mList2, (o1, o2) -> Integer.parseInt(o1.getNumber()) - Integer.parseInt(o2.getNumber()));
        } else if (index == 2) {
            mList3.add(bet);
            Collections.sort(mList3, (o1, o2) -> Integer.parseInt(o1.getNumber()) - Integer.parseInt(o2.getNumber()));
        }
    }

    @Override
    public void random(int... args) {
    }
}
