package com.hz.pm.api.common.util;

import cn.hutool.core.collection.CollUtil;
import com.hz.pm.api.expert.model.DictFieldInfoDTO;

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

/**
 * @author liuxinxin
 * @date 2022/7/28 下午2:14
 */
public class DictUtils {

    private DictUtils() {
    }

    public static Boolean isValueEquals(List<DictFieldInfoDTO> list1, List<DictFieldInfoDTO> 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(DictFieldInfoDTO::getDictionaryFieldName).thenComparing(DictFieldInfoDTO::getDictionaryCode));
        list2.sort(Comparator.comparing(DictFieldInfoDTO::getDictionaryFieldName).thenComparing(DictFieldInfoDTO::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;
    }
}
