package com.cool.store.vo.point;

import cn.hutool.core.map.MapUtil;
import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils;
import com.cool.store.entity.EnterpriseUserDO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author zhangchenbiao
 * @FileName: UserBaseInfoVO
 * @Description:
 * @date 2024-04-08 13:42
 */
@Data
public class UserBaseInfoVO {

    @ApiModelProperty("用户id")
    private String userId;

    @ApiModelProperty("姓名")
    private String username;

    @ApiModelProperty("头像")
    private String avatar;

    public UserBaseInfoVO(String userId, String username, String avatar) {
        this.userId = userId;
        this.username = username;
        this.avatar = avatar;
    }

    public static UserBaseInfoVO convert(String userId, Map<String, EnterpriseUserDO> userMap) {
        if(StringUtils.isBlank(userId) || MapUtil.isEmpty(userMap)){
            return null;
        }
        EnterpriseUserDO user = userMap.get(userId);
        if(Objects.isNull(user)){
            return null;
        }
        return new UserBaseInfoVO(user.getUserId(), user.getName(), user.getAvatar());
    }

    public static List<UserBaseInfoVO> convert(List<String> userIdList, Map<String, EnterpriseUserDO> userMap) {
        if(CollectionUtils.isEmpty(userIdList) || MapUtil.isEmpty(userMap)){
            return null;
        }
        List<UserBaseInfoVO> resultList = new ArrayList<>();
        for (String userId : userIdList) {
            EnterpriseUserDO user = userMap.get(userId);
            if(Objects.isNull(user)){
                continue;
            }
            resultList.add(new UserBaseInfoVO(user.getUserId(), user.getName(), user.getAvatar()));
        }
        return resultList;
    }

}
