package com.yc.ship.module.otc.convert.store;

import com.yc.ship.framework.common.util.collection.CollectionUtils;
import com.yc.ship.framework.common.util.collection.MapUtils;
import com.yc.ship.framework.common.util.object.BeanUtils;
import com.yc.ship.module.otc.controller.admin.store.user.StoreUserRespVO;
import com.yc.ship.module.otc.dal.dataobject.store.StoreUserDO;
import com.yc.ship.module.system.api.user.dto.AdminUserRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

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

@Mapper
public interface StoreUserConvert {

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

    default List<StoreUserRespVO> convertList(List<StoreUserDO> list, Map<Long, AdminUserRespDTO> userMap) {
        return CollectionUtils.convertList(list, storeUser -> {
            StoreUserRespVO userVO = BeanUtils.toBean(storeUser, StoreUserRespVO.class);
            MapUtils.findAndThen(userMap, storeUser.getUserId(), user -> userVO.setUserName(user.getNickname()));
            return userVO;
        });
    }

}
