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


import com.hz.pm.api.common.util.DictUtils;
import com.hz.pm.api.common.util.RegionUtils;
import com.hz.pm.api.common.util.StrUtils;
import com.hz.pm.api.common.util.TagUtils;
import com.hz.pm.api.expert.constant.ExpertSensitiveFieldTypeEnum;
import com.hz.pm.api.expert.constant.ExpertUserInfoSensitiveFieldEnum;
import com.hz.pm.api.meta.model.ExpertRegionInfo;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.util.List;
import java.util.Objects;

/**
 * @author liuxinxin
 * @date 2022/7/28 上午11:28
 */
@Data
@ApiModel("需要审核字段部分")
public class SensitiveModifySegment {

    public SensitiveModifySegment(ExpertUserInfoSensitiveFieldEnum fieldName, Object original, Object apply) {
        this.fieldName = fieldName;
        this.original = original;
        this.apply = apply;
    }

    public SensitiveModifySegment(ExpertSensitiveFieldTypeEnum fieldType, ExpertUserInfoSensitiveFieldEnum fieldName, Object original, Object apply) {
        this.fieldType = fieldType;
        this.fieldName = fieldName;
        this.original = original;
        this.apply = apply;
    }


    private ExpertSensitiveFieldTypeEnum fieldType = ExpertSensitiveFieldTypeEnum.expert_sensitive_info_field;

    private ExpertUserInfoSensitiveFieldEnum fieldName;

    private Object original;

    private Object apply;

    public Boolean isValueEquals() {
        switch (fieldName) {
            case phone_no:
            case email:
            case company:
            case legal_entity_code: {
                return StrUtils.trimEquals((String) this.original, (String) this.apply);
            }
            case administrative_rank:
            case title_level: {
                return DictUtils.isValueEquals((List<DictFieldInfoDTO>) this.original
                        , (List<DictFieldInfoDTO>) this.apply);
            }
            case good_at:
            case technical_expertise:
            case industry_sector:
            case other: {
                return TagUtils.isValueEquals((List<TagFieldInfo>) this.original, (List<TagFieldInfo>) this.apply);
            }
            case expert_region:
                return RegionUtils.isValueEquals((ExpertRegionInfo) this.original, (ExpertRegionInfo) this.apply);
            case expert_intention_work_region:
                return RegionUtils.isValueEquals((List<ExpertRegionInfo>) this.original, (List<ExpertRegionInfo>) this.apply);
            default:
                return Objects.equals(this.original, this.apply);
        }
    }

    public static Boolean isModify(List<SensitiveModifySegment> segmentList) {
        if (CollectionUtils.isEmpty(segmentList)) {
            return false;
        }
        for (SensitiveModifySegment segment : segmentList) {
            if (Boolean.FALSE.equals(segment.isValueEquals())) {
                return true;
            }
        }
        return false;
    }

}
