package com.mvc.iot;

import com.mvc.iot.aep.AepDataHandler;
import com.mvc.model.TaskRemoteCfgModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class IotCommandHandler implements Runnable {
    private static Logger log = LoggerFactory.getLogger(AepDataHandler.class);

    @Resource
    private IotApiHelper iotApiHelper;

    @Override
    public void run() {
        while (true) {
            try {
                TaskRemoteCfgModel tempModel = IotStoreBlockingQueue.iotCommandQueue.take();
                //handleCommand(tempModel);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public void handleCommand(TaskRemoteCfgModel model) throws Exception {
        if (model.getIotCommandType() == 1) {
            iotApiHelper.sendRemoteCfgTask(model);
        } else if (model.getIotCommandType() == 2) {
            iotApiHelper.cancelRemoteCfgTask(model);
        }
    }
}
