package com.ningdatech.pmapi.common.util;

import cn.hutool.core.collection.CollUtil;
import com.ningdatech.pmapi.expert.model.DictionaryFieldInfo;

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

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

public class DictUtils {

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

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