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

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.iotshelves.vo.IotShelvesRespVO;
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 IotShelvesConvert {

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

    default List<IotShelvesRespVO> convertList(List<IotShelvesDO> list, Map<Long, SapOrgRespDTO> sapOrgMap, Map<Long, IotStorageAreaDO> areaMap) {
        return CollectionUtils.convertList(list, shelves -> convert1(shelves, sapOrgMap.get(shelves.getStorageLocationId()),
                areaMap.get(shelves.getStorageAreaId())));
    }

    default IotShelvesRespVO convert1(IotShelvesDO shelves, SapOrgRespDTO sapOrg, IotStorageAreaDO storageArea) {
        IotShelvesRespVO shelvesVO = BeanUtils.toBean(shelves, IotShelvesRespVO.class);
        if (sapOrg != null) {
            shelvesVO.setStorageLocationName(sapOrg.getStorageLocationName());
        }
        if (storageArea != null) {
            shelvesVO.setStorageAreaName(storageArea.getName());
        }
        return shelvesVO;
    }

}
