#ifndef SOIL_MOISTURE_H
#define SOIL_MOISTURE_H

#include <ble/Bluetooth.h>
#include <boost/uuid/uuid.hpp>

namespace trygvis {
namespace soil_moisture {

using namespace trygvis::bluetooth;

enum class sm_cmd_code : uint8_t {
    SM_CMD_GET_SENSOR_COUNT = 1,
    SM_CMD_GET_VALUE = 2,
    SM_CMD_SET_WARNING_VALUE = 3,
    SM_CMD_GET_WARNING_VALUE = 4,
    SM_CMD_SET_SENSOR_NAME = 5,
    SM_CMD_GET_SENSOR_NAME = 6,
    SM_CMD_SET_UPDATE_INTERVAL = 7,
    SM_CMD_FAIL = 255,
};

extern const boost::uuids::uuid soil_moisture_service;
extern const boost::uuids::uuid soil_moisture_characteristic;

class SoilMoisture {
public:
    static SoilMoisture create(BluetoothGatt &gatt);

    uint8_t getSensorCount();

    uint16_t getValue(uint8_t sensor);

private:
    SoilMoisture(BluetoothGatt &gatt, BluetoothGattService &s, BluetoothGattCharacteristic &c);

    ByteBuffer writeAndRead(ByteBuffer &requestBytes);

    BluetoothGatt &gatt;
    BluetoothGattService &s;
    BluetoothGattCharacteristic &c;
};

}
}

#endif