package com.yc.ship.module.miniapplet.convert.adsense;

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.miniapplet.controller.admin.advert.vo.AdvertRespVO;
import com.yc.ship.module.miniapplet.dal.dataobject.adsense.AdsenseDO;
import com.yc.ship.module.miniapplet.dal.dataobject.advert.AdvertDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

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

@Mapper
public interface AdsenseConvert {

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

    default List<AdvertRespVO> convertAdvertList(List<AdvertDO> list, Map<Long, AdsenseDO> adsenseMap) {
        return CollectionUtils.convertList(list, advert -> {
            AdvertRespVO advertVO = BeanUtils.toBean(advert, AdvertRespVO.class);
            MapUtils.findAndThen(adsenseMap, advert.getAdsenseId(), c -> advertVO.setAdsenseName(c.getAdsenseName()));
            return advertVO;
        });
    }


}
