package jnpf.util.attendance;

import jnpf.enums.attendance.ScheduleImportEnum;
import jnpf.model.attendance.model.ScheduleImportFailModel;
import org.apache.commons.compress.utils.Lists;

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

public class RuleExcelImportUtil {

    public static Boolean addFail(Boolean isTrue, ScheduleImportEnum scheduleImportEnum, String userName, List<ScheduleImportFailModel> failList) {
        if (!isTrue) {
            return false;
        }
        if (failList.stream().anyMatch(model -> model.getError().equals(scheduleImportEnum))) {
            failList.stream().filter(model -> model.getError().equals(scheduleImportEnum)).findFirst().ifPresent(scheduleImportFailModel -> scheduleImportFailModel.getUserNames().add(userName));
            return true;
        }
        ArrayList<String> objects = Lists.newArrayList();
        objects.add(userName);
        failList.add(ScheduleImportFailModel.builder().error(scheduleImportEnum).userNames(objects).build());
        return true;
    }
}
