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

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.iotcargolocation.vo.IotCargoLocationRespVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.iotcargolocation.IotCargoLocationDO;
import cn.iocoder.yudao.module.pms.dal.dataobject.iotshelves.IotShelvesDO;
import cn.iocoder.yudao.module.pms.dal.dataobject.iotstoragearea.IotStorageAreaDO;
import cn.iocoder.yudao.module.system.api.saporg.dto.SapOrgRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

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

@Mapper
public interface IotCargoLocationConvert {

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

    default List<IotCargoLocationRespVO> convertList(List<IotCargoLocationDO> list, Map<Long, SapOrgRespDTO> sapOrgMap,
                                                     Map<Long, IotStorageAreaDO> areaMap, Map<Long, IotShelvesDO> shelvesMap) {
        return CollectionUtils.convertList(list, cargo -> convert1(cargo, sapOrgMap.get(cargo.getStorageLocationId()),
                areaMap.get(cargo.getStorageAreaId()), shelvesMap.get(cargo.getShelvesId())));
    }

    default IotCargoLocationRespVO convert1(IotCargoLocationDO cargoLocation, SapOrgRespDTO sapOrg,
                                            IotStorageAreaDO storageArea, IotShelvesDO shelves) {
        IotCargoLocationRespVO cargoLocationVO = BeanUtils.toBean(cargoLocation, IotCargoLocationRespVO.class);
        if (sapOrg != null) {
            cargoLocationVO.setStorageLocationName(sapOrg.getStorageLocationName());
        }
        if (storageArea != null) {
            cargoLocationVO.setStorageAreaName(storageArea.getName());
        }
        if (shelves != null) {
            cargoLocationVO.setShelvesName(shelves.getName());
        }
        return cargoLocationVO;
    }

}
