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 BEH0377 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.getName().indexOf("配偶") != -1
                                && i.getDead() != null
                                && StringUtil.isNotBlank(i.getDead().getName())
                )
                .collect(Collectors.toList());

        if (familyList.size() > 0) {
            status.set("-1");
            long count = familyList
                    .stream()
                    .filter(
                            i -> i.getDead().getPd() != null && StringUtil.isNotBlank(i.getDead().getPd().getName())
                    )
                    .count();
            if (count > 0) {
                status.set("0");
            }
        }
    }

}