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

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.iotstoragearea.vo.IotStorageAreaRespVO;
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 IotStorageAreaConvert {

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

    default List<IotStorageAreaRespVO> convertList(List<IotStorageAreaDO> list, Map<Long, SapOrgRespDTO> sapOrgMap) {
        return CollectionUtils.convertList(list, area -> convert(area, sapOrgMap.get(area.getStorageLocationId())));
    }

    default IotStorageAreaRespVO convert(IotStorageAreaDO storageArea, SapOrgRespDTO sapOrg) {
        IotStorageAreaRespVO areaVO = BeanUtils.toBean(storageArea, IotStorageAreaRespVO.class);
        if (sapOrg != null) {
            areaVO.setStorageLocationName(sapOrg.getStorageLocationName());
        }
        return areaVO;
    }

}
