package com.tmerclub.cloud.systemtest.data.platform;

import cn.hutool.core.bean.BeanUtil;
import com.moyuer.cloud.systemtest.api.platform.UserLevelApi;
import com.tmerclub.cloud.user.dto.UserLevelDTO;
import com.tmerclub.cloud.user.dto.UserLevelTermDTO;
import com.tmerclub.cloud.user.vo.UserLevelTermVO;
import com.tmerclub.cloud.user.vo.UserLevelVO;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author lpj
 */
public class UserLevelDtoData {
    public static UserLevelDTO getUserLevelDTO(Long userLevelId, List<Long> userRightsIds) {
        UserLevelVO userLevelVO = UserLevelApi.info(userLevelId);
        UserLevelDTO userLevelDTO = new UserLevelDTO();
        BeanUtils.copyProperties(userLevelVO, userLevelDTO);

        List<UserLevelTermVO> userLevelTerms = userLevelVO.getUserLevelTerms();
        List<UserLevelTermDTO> userLevelTermDTOList = userLevelTerms.stream().map(i -> BeanUtil.copyProperties(i, UserLevelTermDTO.class)).collect(Collectors.toList());
        userLevelDTO.setUserLevelTerms(userLevelTermDTOList);

        userLevelDTO.setUserRightsIds(userRightsIds);

        return userLevelDTO;
    }
}
