package cn.iocoder.yudao.module.pms.convert.iotlockstock;

import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.pms.controller.admin.iotlockstock.vo.IotLockStockRespVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.iotlockstock.IotLockStockDO;
import cn.iocoder.yudao.module.system.api.saporg.dto.SapOrgRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Mapper
public interface IotLockStockConvert {

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

    default List<IotLockStockRespVO> convertList(List<IotLockStockDO> list, Map<Long, SapOrgRespDTO> factoryMap,
                                                 Map<Long, SapOrgRespDTO> costCenterMap, BigDecimal totalQuantity, BigDecimal totalAmount) {
        return CollectionUtils.convertList(list, lockStock -> convert1(lockStock, factoryMap.get(lockStock.getFactoryId()),
                costCenterMap.get(lockStock.getCostCenterId()), totalQuantity, totalAmount));
    }

    default IotLockStockRespVO convert1(IotLockStockDO lockStock, SapOrgRespDTO factory,
                                        SapOrgRespDTO costCenter, BigDecimal totalQuantity, BigDecimal totalAmount) {
        IotLockStockRespVO lockStockVO = BeanUtils.toBean(lockStock, IotLockStockRespVO.class);
        if (factory != null) {
            lockStockVO.setFactory(factory.getFactoryName());
        }
        if (costCenter != null) {
            lockStockVO.setCostCenter(costCenter.getCostCenterName());
        }
        lockStockVO.setTotalQuantity(totalQuantity);
        lockStockVO.setTotalAmount(totalAmount);
        return lockStockVO;
    }

}
