"use strict";
import Luci from "../luci.js";
import Api from "./api.js";

class ApiMqttIn {

    static luciReceived = [];
    static readStatusLuci = (outVal,payloadJSON) => {
        // TODO find connection IN-OUT
        const l = Luci.createLight('test'+Date.now(),payloadJSON.stato,'in'+ApiMqttIn.luciReceived.length,outVal);
        ApiMqttIn.luciReceived.push(l);
        if(ApiMqttIn.luciReceived.length >= 8){
            Api.sendLuciWeb(ApiMqttIn.luciReceived);
            ApiMqttIn.luciReceived = [];
        }
    }

    static outForToggleLuciStato = null;//out0/.../out7
    static statoLuce = (outVal,payloadJSON) => {
        if(ApiMqttIn.outForToggleLuciStato.out === outVal && ApiMqttIn.outForToggleLuciStato.stato === payloadJSON.stato){
            Api.sendLuciStatoWeb();
            ApiMqttIn.outForToggleLuciStato = null;
        }
    }

}

export default ApiMqttIn;