package com.skr.mdm.service.impl.equipment;

import com.skr.mdm.annotation.CmdHandler;
import com.skr.mdm.constant.CmdTypeConstants;
import com.skr.mdm.dao.DeviceEquipmentDao;
import com.skr.mdm.dto.EquipmentCardBindStateDTO;
import com.skr.mdm.entity.DeviceEquipmentDO;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.service.CmdHandlerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 获取机卡绑定状态
 *
 * @author nfq
 * @date 2023-03-07 17:26
 */
@Slf4j
@CmdHandler(cmdType = CmdTypeConstants.CARD_BIND_STATE)
public class EquipmentCardBindStateServiceImpl implements CmdHandlerService {

    @Autowired
    private DeviceEquipmentDao equipmentDao;

    @Override
    public ResponseResult cmdHandler(Integer equipmentId, String data) {
        try {
            DeviceEquipmentDO equipmentDO = equipmentDao.selectById(equipmentId);
            EquipmentCardBindStateDTO equipmentCardBindStateDTO = EquipmentCardBindStateDTO.builder()
                    .bindState(equipmentDO.getIsCardBinding())
                    .iccid(equipmentDO.getIccid())
                    .build();
            return ResponseResult.success(equipmentCardBindStateDTO);
        } catch (Exception e) {
            log.error("查询机卡绑定状态异常: " + equipmentId + data, e);
            return ResponseResult.failure();
        }
    }
}