//
// Created by cynthya on 1/27/23.
//

#ifndef CLIENT_MOCK_COMPRESSEDDATAPACKAGE_HPP
#define CLIENT_MOCK_COMPRESSEDDATAPACKAGE_HPP

#include <ArduinoJson.h>
#include <list>
#include <string>
#include <utility>
#include "ErrorTypes.h"

// null timestamp


struct CompressedDataPackage {
  int channel;    // can this be short?
  int i2cAddress; // can this be short?
  double value;
  unsigned long timestamp;
  ErrorTypes errorType;
  HardwareName hardwareName;
  SensorProtocol sensorProtocol;
  MeasurementType measurementType;
  // same could be done for hardwarename and sensorprotocol

  // tostring
  [[nodiscard]] std::string toString() const {
    StaticJsonDocument<250> document; // 250 byte is the max send size of espnow

    document["hardwareName"] =
        HardwareNames::hardwareNameToString(hardwareName);
    document["timestamp"] = timestamp;
    document["sensorProtocol"] =
        SensorProtocols::sensorProtocolToString(sensorProtocol);
    document["value"] = value;

    if (channel != -1) {
      document["channel"] = channel;
    }

    if (i2cAddress != -1) {
      document["i2cAddress"] = i2cAddress;
    }

    document["measurementType"] =
        MeasurementTypes::measurementTypeToString(measurementType);

    std::string jsonString;
    serializeJson(document, jsonString);
    return jsonString;
  }
};

#endif // CLIENT_MOCK_COMPRESSEDDATAPACKAGE_HPP