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

import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.api.equipment.dto.AttendanceUpdateDTO;
import cn.iocoder.yudao.module.system.api.equipment.dto.DistributeRecordDTO;
import cn.iocoder.yudao.module.system.controller.admin.equipment.vo.attendancemachine.AddUserToAttendanceMachineVO;
import cn.iocoder.yudao.module.system.controller.admin.equipment.vo.attendancemachine.AttendanceMachinePasswordVO;
import cn.iocoder.yudao.module.system.dal.dataobject.equipment.DistributeRecordDO;
import cn.iocoder.yudao.module.system.service.equipment.AttendanceMachineService;
import cn.iocoder.yudao.module.system.service.equipment.DistributeRecordService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class AttendanceMachineApiImpl implements AttendanceMachineApi{

    @Resource
    private AttendanceMachineService attendanceMachineService;

    @Resource
    private DistributeRecordService distributeRecordService;

    @Override
    public void createDistributeRecord(List<DistributeRecordDTO> recordDTO) {

        List<DistributeRecordDO> distributeRecordDO = BeanUtils.toBean(recordDTO, DistributeRecordDO.class);

        distributeRecordService.createDistributeRecord(distributeRecordDO);
    }

    @Override
    public void updateDistributeRecord(List<DistributeRecordDTO> recordDTO) {

        distributeRecordService.updateDistributeRecord(BeanUtils.toBean(recordDTO, DistributeRecordDO.class));
    }

    @Override
    public void updateAttendance(AttendanceUpdateDTO updateDTO) {

        AddUserToAttendanceMachineVO updateVO = BeanUtils.toBean(updateDTO, AddUserToAttendanceMachineVO.class);
        attendanceMachineService.addUserToAttendanceMachine(updateVO);
    }

    @Override
    public void updateDevicePassword(String deviceNo, String oldPassword, String newPassword) {

        AttendanceMachinePasswordVO passwordVO = new AttendanceMachinePasswordVO();
        passwordVO.setDeviceNo(deviceNo);
        passwordVO.setOldPassword(oldPassword);
        passwordVO.setNewPassword(newPassword);
        attendanceMachineService.updatePassword(passwordVO);
    }
}
