package com.cy.guoyan.admin.module.system.convert.user;

import com.cy.guoyan.admin.framework.common.util.collection.CollectionUtils;
import com.cy.guoyan.admin.framework.common.util.object.BeanUtils;
import com.cy.guoyan.admin.module.system.controller.admin.permission.vo.role.RoleSimpleRespVO;
import com.cy.guoyan.admin.module.system.controller.admin.user.vo.profile.UserProfileRespVO;
import com.cy.guoyan.admin.module.system.controller.admin.user.vo.user.UserRespVO;
import com.cy.guoyan.admin.module.system.controller.admin.user.vo.user.UserSimpleRespVO;
import com.cy.guoyan.admin.module.system.dal.dataobject.permission.RoleDO;
import com.cy.guoyan.admin.module.system.dal.dataobject.user.AdminUserDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Map;

@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(AdminUserDO user, List<RoleDO> userRoles) {
        UserProfileRespVO userVO = BeanUtils.toBean(user, UserProfileRespVO.class);
        userVO.setRoles(BeanUtils.toBean(userRoles, RoleSimpleRespVO.class));
        return userVO;
    }

}
