package com.ningdatech.pmapi.common.util;

import com.ningdatech.pmapi.meta.model.ExpertRegionInfo;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Comparator;
import java.util.List;

/**
 * @author liuxinxin
 * @date 2022/7/28 下午2:27
 */

public class RegionUtils {

    public static Boolean isValueEquals(ExpertRegionInfo regionInfo1, ExpertRegionInfo regionInfo2) {
        if (null == regionInfo1.getRegionCode() && null == regionInfo1.getRegionLevel()) {
            return false;
        }
        return regionInfo1.getRegionCode().equals(regionInfo2.getRegionCode())
                && regionInfo1.getRegionLevel().equals(regionInfo2.getRegionLevel());
    }

    public static Boolean isValueEquals(List<ExpertRegionInfo> list1, List<ExpertRegionInfo> list2) {
        if (CollectionUtils.isEmpty(list1) && CollectionUtils.isEmpty(list2)) {
            return true;
        }
        boolean collectionStatusNotEquals = (CollectionUtils.isEmpty(list1) && CollectionUtils.isNotEmpty(list2))
                || (CollectionUtils.isEmpty(list2) && CollectionUtils.isNotEmpty(list1));
        if (collectionStatusNotEquals) {
            return false;
        }
        if (list1.size() != list2.size()) {
            return false;
        }
        list1.sort(Comparator.comparing(ExpertRegionInfo::getRegionCode).thenComparing(ExpertRegionInfo::getRegionLevel));
        list2.sort(Comparator.comparing(ExpertRegionInfo::getRegionCode).thenComparing(ExpertRegionInfo::getRegionLevel));

        for (int i = 0; i < list1.size(); i++) {
            if (!StrUtils.trimEquals(list1.get(i).getRegionCode(), list2.get(i).getRegionCode())
                    || !list1.get(i).getRegionLevel().equals(list2.get(i).getRegionLevel())) {
                return false;
            }
        }
        return true;
    }
}
