package cn.iocoder.yudao.module.system.convert.equipment;

import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.equipment.vo.attendancemachine.AttendanceMachineRespVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
import cn.iocoder.yudao.module.system.dal.dataobject.equipment.AttendanceMachineDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

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

@Mapper
public interface AttendanceMachineConvert {

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

    default List<AttendanceMachineRespVO> convertList(List<AttendanceMachineDO> list, Map<Long, DeptDO> deptMap) {

        return CollectionUtils.convertList(list, data -> convert(data, deptMap.get(data.getDeptId())));
    }

    default AttendanceMachineRespVO convert(AttendanceMachineDO attendanceMachineDO, DeptDO deptDO) {

        AttendanceMachineRespVO respVO = new AttendanceMachineRespVO();
        if (attendanceMachineDO != null) {

            respVO = BeanUtils.toBean(attendanceMachineDO, AttendanceMachineRespVO.class);
            respVO.setIsOnLine(attendanceMachineDO.getStatus());

            if (deptDO != null) {
                respVO.setDeptName(deptDO.getName());
            }
        }

        return respVO;
    }
}
