#pragma once
#include <ArduinoJson.h>
#include "RC.h"

class Protocol {
protected:
    unsigned int protocol;

public:
    Protocol(unsigned int protocol) {
        this->protocol = protocol;
    }
    virtual ~Protocol() {}

    virtual void fromJson(JsonObjectConst& rcSwitch, RCSwitch& rcDevice) {
        unsigned int protocol = rcSwitch["protocol"];
        rcDevice.setProtocol(protocol);
    	mySwitch.enableTransmit(SEND_PIN);
        rcDevice.send(rcSwitch["value"]);
    	mySwitch.disableTransmit();
    }

    virtual void toJson(unsigned long value, JsonDocument& jsonDoc) {
        JsonObject rcSwitch = jsonDoc.createNestedObject("rcSwitch");
        rcSwitch["protocol"] = protocol;
        rcSwitch["value"] = value;
    }

};