package com.lantone.qc.kernel.catalogue.behospitalized;

import com.google.common.collect.Lists;
import com.lantone.qc.kernel.catalogue.QCCatalogue;
import com.lantone.qc.pub.model.InputInfo;
import com.lantone.qc.pub.model.OutputInfo;
import com.lantone.qc.pub.model.entity.Family;
import com.lantone.qc.pub.util.ListUtil;
import com.lantone.qc.pub.util.StringUtil;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 家属有死亡者, 未记录死亡年龄
 * @author: rengb
 * @time: 2020/3/10 14:02
 */
@Component
public class BEH0399 extends QCCatalogue {

    @Override
    public void start(InputInfo inputInfo, OutputInfo outputInfo) {
        status.set("0");
        if (inputInfo.getBeHospitalizedDoc() == null) {
            return;
        }
        List<Family> familyList = Lists.newArrayList();
        List<Family> familiesFl = inputInfo.getBeHospitalizedDoc().getFamilyLabel().getFamilies();
        List<Family> familiesMl = inputInfo.getBeHospitalizedDoc().getMaritalLabel().getFamily();
        if (ListUtil.isNotEmpty(familiesFl)) {
            familyList.addAll(familiesFl);
        }
        if (ListUtil.isNotEmpty(familiesMl)) {
            familyList.addAll(familiesMl);
        }

        familyList = familyList
                .stream()
                .filter(
                        i -> i != null
                                && StringUtil.isNotBlank(i.getName())
                                && i.getDead() != null
                                && StringUtil.isNotBlank(i.getDead().getName())
                )
                .collect(Collectors.toList());

        if (familyList.size() > 0) {
            long count = familyList
                    .stream()
                    .filter(
                            i -> i.getDead().getAge() == null || StringUtil.isBlank(i.getDead().getAge().getName())
                    )
                    .count();
            if (count > 0) {
                status.set("-1");
            }
        }
    }

}