package com.ningdatech.pmapi.common.util;

import com.ningdatech.pmapi.expert.model.TagFieldInfo;
import org.apache.commons.collections4.CollectionUtils;

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

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

    private TagUtils() {
    }

    public static Boolean isValueEquals(List<TagFieldInfo> list1, List<TagFieldInfo> 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(TagFieldInfo::getTagFieldName).thenComparing(TagFieldInfo::getTagCode));
        list2.sort(Comparator.comparing(TagFieldInfo::getTagFieldName).thenComparing(TagFieldInfo::getTagCode));

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