#pragma once
#include <Arduino.h>
#include <SimpleSerialProtocol.h>
#include <Temperature.h>
#include <RFTransmit.h>
#include <DistanceSensor.h>
namespace Connection
{
    SimpleSerialProtocol debugger;
    SimpleSerialProtocol networker;

    void init();
    void handle();
    void onNetworkerPacket(Packet packet);
};

void Connection::init() {
    debugger.init(0, 115200);
    debugger.sendPacket("debugger", "serial_status", "ready");

    networker.init(2, 115200);
    networker.sendPacket("networker", "serial_status", "ready");
}

void Connection::handle() {
    networker.receivePackets(onNetworkerPacket);

    Temperature::handle(&networker);
    // DistanceSensor::handle(&networker);
}

void Connection::onNetworkerPacket(Packet packet) {

    // Handle Lights
    if (strcmp(packet.id, "ambiance_light") == 0) {
    debugger.sendPacket(packet.id, packet.command, packet.data);

        RFTransmit::handlePacket(&networker, packet.id, packet.command, packet.data);
    }
}