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

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.iotdevicecategorytemplate.vo.IotDeviceCategoryTemplateRespVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.IotProductClassifyDO;
import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicecategorytemplate.IotDeviceCategoryTemplateDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

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

@Mapper
public interface IotDeviceCategoryTemplateConvert {

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

    default List<IotDeviceCategoryTemplateRespVO> convertList(List<IotDeviceCategoryTemplateDO> list, Map<Long, IotProductClassifyDO> productClassifyMap) {
        return CollectionUtils.convertList(list, template -> convert(template, productClassifyMap.get(template.getDeviceCategoryId())));
    }

    default IotDeviceCategoryTemplateRespVO convert(IotDeviceCategoryTemplateDO template, IotProductClassifyDO deviceCategory) {
        IotDeviceCategoryTemplateRespVO templateVO = BeanUtils.toBean(template, IotDeviceCategoryTemplateRespVO.class);
        if (deviceCategory != null) {
            templateVO.setDeviceCategoryName(deviceCategory.getName());
        }
        return templateVO;
    }

}
