package com.cool.store.vo;

import com.cool.store.entity.EnterpriseUserDO;
import com.google.common.collect.Lists;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Author suzhuhong
 * @Date 2023/6/15 14:31
 * @Version 1.0
 */
@Data
public class EnterpriseUserSingleInfoVO {

    private String userId;

    private String userName;

    private String mobile;

    public static List<EnterpriseUserSingleInfoVO> convertVO(List<EnterpriseUserDO> userList){
        if(CollectionUtils.isEmpty(userList)){
            return Lists.newArrayList();
        }
        Map<String, String> userIdMap = new HashMap<>();
        List<EnterpriseUserSingleInfoVO> resultList = new ArrayList<>();
        for (EnterpriseUserDO enterpriseUser : userList) {
            String userId = enterpriseUser.getUserId();
            boolean isContains = userIdMap.containsKey(userId);
            if(!isContains){
                EnterpriseUserSingleInfoVO result = new EnterpriseUserSingleInfoVO();
                result.setUserId(userId);
                result.setUserName(enterpriseUser.getName());
                result.setMobile(enterpriseUser.getMobile());
                resultList.add(result);
                userIdMap.put(userId, userId);
            }
        }
        return resultList;
    }
}
