package com.jeelowcode.service.system.config.convert.user;

import com.jeelowcode.tool.framework.common.util.collection.CollectionUtils;
import com.jeelowcode.tool.framework.common.util.object.BeanUtils;
import com.jeelowcode.service.system.controller.vo.user.profile.UserProfileRespVO;
import com.jeelowcode.service.system.controller.vo.user.user.UserRespVO;
import com.jeelowcode.service.system.controller.vo.user.user.UserSimpleRespVO;
import com.jeelowcode.service.system.entity.SocialUserDO;
import com.jeelowcode.service.system.entity.AdminUserDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface UserConvert {

    UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);

    default List<UserRespVO> convertList(List<AdminUserDO> list) {
        return CollectionUtils.convertList(list, user -> convert(user));
    }

    default UserRespVO convert(AdminUserDO user) {
        UserRespVO userVO = BeanUtils.toBean(user, UserRespVO.class);
        return userVO;
    }

    default List<UserSimpleRespVO> convertSimpleList(List<AdminUserDO> list) {
        return CollectionUtils.convertList(list, user -> {
            UserSimpleRespVO userVO = BeanUtils.toBean(user, UserSimpleRespVO.class);
            return userVO;
        });
    }

    default UserProfileRespVO convert(List<SocialUserDO> socialUsers,
                                     AdminUserDO user) {
        UserProfileRespVO userVO = BeanUtils.toBean(user, UserProfileRespVO.class);
        userVO.setSocialUsers(BeanUtils.toBean(socialUsers, UserProfileRespVO.SocialUser.class));
        return userVO;
    }

}
