package com.yc.ship.module.ota.convert.distrbutor;

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.ota.controller.admin.distributoraudit.vo.DistributorAuditRespVO;
import com.yc.ship.module.ota.controller.admin.distributorauditlog.vo.DistributorAuditLogRespVO;
import com.yc.ship.module.ota.controller.admin.tradelog.vo.TradeLogRespVO;
import com.yc.ship.module.ota.dal.dataobject.distributor.DistributorDO;
import com.yc.ship.module.ota.dal.dataobject.distributoraudit.DistributorAuditDO;
import com.yc.ship.module.ota.dal.dataobject.distributorauditlog.DistributorAuditLogDO;
import com.yc.ship.module.ota.dal.dataobject.tradelog.TradeLogDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

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

@Mapper
public interface DistributorConvert {

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

    default List<DistributorAuditRespVO> convertAuditList(List<DistributorAuditDO> list, Map<Long, DistributorDO> distributorMap) {
        return CollectionUtils.convertList(list, distributorAudit -> {
            DistributorAuditRespVO distributorAuditVO = BeanUtils.toBean(distributorAudit, DistributorAuditRespVO.class);
            MapUtils.findAndThen(distributorMap, distributorAudit.getDistributorId(), distributor -> distributorAuditVO.setDistributorName(distributor.getName()));
            return distributorAuditVO;
        });
    }

    default List<DistributorAuditLogRespVO> convertAuditLogList(List<DistributorAuditLogDO> list, Map<Long, DistributorDO> distributorMap) {
        return CollectionUtils.convertList(list, distributorAuditLog -> {
            DistributorAuditLogRespVO distributorAuditLogVO = BeanUtils.toBean(distributorAuditLog, DistributorAuditLogRespVO.class);
            MapUtils.findAndThen(distributorMap, distributorAuditLogVO.getDistributorId(), distributor -> distributorAuditLogVO.setDistributorName(distributor.getName()));
            return distributorAuditLogVO;
        });
    }

    default List<TradeLogRespVO> convertTradeLogList(List<TradeLogDO> list, Map<Long, DistributorDO> distributorMap) {
        return CollectionUtils.convertList(list, tradeLog -> {
            TradeLogRespVO tradeLogVO = BeanUtils.toBean(tradeLog, TradeLogRespVO.class);
            MapUtils.findAndThen(distributorMap, tradeLogVO.getDistributorId(), distributor -> tradeLogVO.setDistributorName(distributor.getName()));
            return tradeLogVO;
        });
    }

}
