package cn.iocoder.yudao.module.smartfactory.convert.cameradevice;

import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.smartfactory.controller.admin.device.cameradevice.vo.CameraSimpleRespVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.factoryinfo.vo.FactorySimpleRespVO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.device.cameradevice.CameraDeviceDO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.factoryinfo.FactoryInfoDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

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

@Mapper
public interface CameraDeviceConvert {

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

    default List<FactorySimpleRespVO> convertList(List<FactoryInfoDO> infoDOS, Map<Long, List<CameraDeviceDO>> cameraMap) {

        return CollectionUtils.convertList(infoDOS, data -> convert(data, cameraMap.get(data.getId())));
    }

    default FactorySimpleRespVO convert(FactoryInfoDO infoDO, List<CameraDeviceDO> cameraDeviceDOS) {

        if (CollectionUtil.isEmpty(cameraDeviceDOS)) {
            return null;
        }

        FactorySimpleRespVO respVO = BeanUtils.toBean(infoDO, FactorySimpleRespVO.class);

        List<CameraSimpleRespVO> cameraList = BeanUtils.toBean(cameraDeviceDOS, CameraSimpleRespVO.class);

        return respVO.setSubsidiary(cameraList);
    }
}
