package cz.senslog.connector.model.azure;

import cz.senslog.connector.tools.util.NumberUtils;
import org.apache.logging.log4j.util.BiConsumer;

import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * The class {@code SensorData} represents transfer object of measure
 * data from each sensor depends on time.
 *
 * @author Lukas Cerny
 * @version 1.0
 * @since 1.0
 */
public class SensorData {

    /** Timestamp when values were measured. */
    private OffsetDateTime time;

    /** Value of temperature in celsius degree (°C). */
    private Float temperature;

    /** Value of humidity. */
    private Float humidity;

    /** Value of carbon dioxide (CO2). */
    private Float co2;

    /** Received signal strength indication (RSSI). */
    private Integer rssi;

    /** Signal to noise ratio (SNR). */
    private Float snr;

    /** Value of battery level. */
    private Float batteryLevel;

    private Integer vitality;

    private Integer rumination;

    private Integer pedometer;

    private Float pH;

    private Integer ORP;

    public OffsetDateTime getTime() {
        return time;
    }

    public void setTime(OffsetDateTime time) {
        this.time = time;
    }

    public Float getTemperature() {
        return temperature;
    }

    public void setTemperature(Float temperature) {
        this.temperature = temperature;
    }

    public Float getHumidity() {
        return humidity;
    }

    public void setHumidity(Float humidity) {
        this.humidity = humidity;
    }

    public Float getCo2() {
        return co2;
    }

    public void setCo2(Float co2) {
        this.co2 = co2;
    }

    public Integer getRssi() {
        return rssi;
    }

    public void setRssi(Integer rssi) {
        this.rssi = rssi;
    }

    public Float getSnr() {
        return snr;
    }

    public void setSnr(Float snr) {
        this.snr = snr;
    }

    public Float getBatteryLevel() {
        return batteryLevel;
    }

    public void setBatteryLevel(Float batteryLevel) {
        this.batteryLevel = batteryLevel;
    }

    public Integer getVitality() {
        return vitality;
    }

    public void setVitality(Integer vitality) {
        this.vitality = vitality;
    }

    public Integer getRumination() {
        return rumination;
    }

    public void setRumination(Integer rumination) {
        this.rumination = rumination;
    }

    public Integer getPedometer() {
        return pedometer;
    }

    public void setPedometer(Integer pedometer) {
        this.pedometer = pedometer;
    }

    public Float getpH() {
        return pH;
    }

    public void setpH(Float pH) {
        this.pH = pH;
    }

    public Integer getORP() {
        return ORP;
    }

    public void setORP(Integer ORP) {
        this.ORP = ORP;
    }

    public Map<String, Float> getValues() {
        Map<String, Float> values = new HashMap<>();
        BiConsumer<String, Float> setValue = (type, value) -> {
          if (value != null) { values.put(type, value); }
        };

        setValue.accept("batteryLevel", batteryLevel);
        setValue.accept("snr", snr);
        setValue.accept("rssi", NumberUtils.valueOf(rssi));
        setValue.accept("co2", co2);
        setValue.accept("humidity", humidity);
        setValue.accept("temperature", temperature);

        setValue.accept("vitality", NumberUtils.valueOf(vitality));
        setValue.accept("rumination", NumberUtils.valueOf(rumination));
        setValue.accept("pedometer", NumberUtils.valueOf(pedometer));
        setValue.accept("pH", pH);
        setValue.accept("ORP", NumberUtils.valueOf(ORP));

        return values;
    }
}
