package com.hz.pm.api.expert.model.bo;


import com.hz.pm.api.expert.constant.ExpertSensitiveFieldTypeEnum;
import com.hz.pm.api.expert.model.SensitiveModifySegment;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

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

/**
 * @author liuxinxin
 * @date 2022/7/28 上午11:18
 */
@Data
public class ExpertInfoSensitiveFieldCheckBO {

    private Boolean hasModify;

    /**
     * 专家敏感信息是否修改
     */
    private Boolean isExpertSensitiveInfoModify;

    /**
     * 专家敏感信息原值和申请值
     */
    private List<SensitiveModifySegment> expertSensitiveInfoFieldSegmentList;

    /**
     * 专家层级是否修改
     */
    private Boolean isExpertRegionModify;
    /**
     * 专家层级修改原值和申请值
     */
    private List<SensitiveModifySegment> expertRegionFieldSegmentList;

    /**
     * 专家履职意向是否修改
     */
    private Boolean isExpertIntentionModify;

    /**
     * 专家履职意向修改原值和申请值
     */
    private List<SensitiveModifySegment> expertIntentionFieldSegmentList;

    public ExpertInfoSensitiveFieldCheckBO(List<SensitiveModifySegment> sensitiveModifySegmentList) {
        Map<ExpertSensitiveFieldTypeEnum, List<SensitiveModifySegment>> collect = sensitiveModifySegmentList
                .stream().collect(Collectors.groupingBy(SensitiveModifySegment::getFieldType));

        this.expertSensitiveInfoFieldSegmentList = collect.get(ExpertSensitiveFieldTypeEnum.expert_sensitive_info_field);
        if (CollectionUtils.isEmpty(expertSensitiveInfoFieldSegmentList)) {
            this.expertSensitiveInfoFieldSegmentList = new ArrayList<>();
        }
        this.isExpertSensitiveInfoModify = SensitiveModifySegment.isModify(expertSensitiveInfoFieldSegmentList);

        this.expertRegionFieldSegmentList = collect.get(ExpertSensitiveFieldTypeEnum.expert_region_field);
        if (CollectionUtils.isEmpty(expertRegionFieldSegmentList)) {
            this.expertRegionFieldSegmentList = new ArrayList<>();
        }
        this.isExpertRegionModify = SensitiveModifySegment.isModify(expertRegionFieldSegmentList);

        this.expertIntentionFieldSegmentList = collect.get(ExpertSensitiveFieldTypeEnum.expert_intention_field);
        if (CollectionUtils.isEmpty(expertIntentionFieldSegmentList)) {
            this.expertIntentionFieldSegmentList = new ArrayList<>();
        }
        this.isExpertIntentionModify = SensitiveModifySegment.isModify(expertIntentionFieldSegmentList);

        this.hasModify = this.isExpertSensitiveInfoModify || this.isExpertRegionModify || this.isExpertIntentionModify;
    }


}
