package com.yc.ship.module.resource.convert.channel;

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.resource.controller.admin.channel.vo.ScenicChannelRespVO;
import com.yc.ship.module.resource.dal.dataobject.channel.ScenicChannelDO;
import com.yc.ship.module.resource.dal.dataobject.site.ScenicSiteDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

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

@Mapper
public interface ChannelConvert {

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

    default List<ScenicChannelRespVO> convertList(List<ScenicChannelDO> list, Map<Long, ScenicSiteDO> siteMap) {
        return CollectionUtils.convertList(list, scenicChannel -> {
            ScenicChannelRespVO channelVO = BeanUtils.toBean(scenicChannel, ScenicChannelRespVO.class);
//            MapUtils.findAndThen(siteMap, scenicChannel.getSiteId(), site -> channelVO.setSiteName(site.getName()));
//            MapUtils.findAndThen(siteMap, scenicChannel.getSiteId(), site -> channelVO.setSiteType(site.getSiteType()));
            MapUtils.findAndThen(siteMap, scenicChannel.getSiteId(), site -> {
                channelVO.setSiteName(site.getName());
                channelVO.setSiteType(site.getSiteType());
            });
            return channelVO;
        });
    }

}
