package cz.senslog.connector.model.azure;

import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.util.List;

import static cz.senslog.connector.tools.json.BasicJson.objectToJson;
import static java.lang.Boolean.TRUE;

/**
 * The class {@code SensorInfo} represents transfer object of sensors.
 *
 * @author Lukas Cerny
 * @version 1.0
 * @since 1.0
 */
public class SensorInfo {

    /** Identifier of sensor. */
    private String eui;

    /** Name of sensor. */
    private String name;

    /** Acronym of sensor. */
    private String acronym;

    /**  */
    private Integer period;

    /**  */
    private Integer tolerance;

    /** Place where the sensor is located. */
    private String location;

    /** Description of what sensor does. */
    private String description;

    /** */
    private Long sensorDataId;

    /**  */
    private OffsetDateTime sensorDataTime;

    /** Time when sensor was created and started to produce data. */
    private LocalDateTime created;

    /** Time when sensor was deleted and stopped to produce data. */
    private LocalDateTime deleted;

    /** Status of sensor: 0 - inactive, 1 - active. */
    private Integer status;

    /** List of measured data */
    private List<SensorData> data;

    public SensorInfo(SensorInfo sensorInfo, List<SensorData> newData) {
        this.eui = sensorInfo.eui;
        this.name = sensorInfo.name;
        this.acronym = sensorInfo.acronym;
        this.period = sensorInfo.period;
        this.tolerance = sensorInfo.tolerance;
        this.location = sensorInfo.location;
        this.description = sensorInfo.description;
        this.sensorDataId = sensorInfo.sensorDataId;
        this.sensorDataTime = sensorInfo.sensorDataTime;
        this.created = sensorInfo.created;
        this.deleted = sensorInfo.deleted;
        this.status = sensorInfo.status;
        this.data = newData;
    }

    public SensorInfo() {}

    public String getEui() {
        return eui;
    }

    public void setEui(String eui) {
        this.eui = eui;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAcronym() {
        return acronym;
    }

    public void setAcronym(String acronym) {
        this.acronym = acronym;
    }

    public Integer getPeriod() {
        return period;
    }

    public void setPeriod(Integer period) {
        this.period = period;
    }

    public Integer getTolerance() {
        return tolerance;
    }

    public void setTolerance(Integer tolerance) {
        this.tolerance = tolerance;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Long getSensorDataId() {
        return sensorDataId;
    }

    public void setSensorDataId(Long sensorDataId) {
        this.sensorDataId = sensorDataId;
    }

    public OffsetDateTime getSensorDataTime() {
        return sensorDataTime;
    }

    public void setSensorDataTime(OffsetDateTime sensorDataTime) {
        this.sensorDataTime = sensorDataTime;
    }

    public LocalDateTime getCreated() {
        return created;
    }

    public void setCreated(LocalDateTime created) {
        this.created = created;
    }

    public LocalDateTime getDeleted() {
        return deleted;
    }

    public void setDeleted(LocalDateTime deleted) {
        this.deleted = deleted;
    }

    public Boolean getStatus() {
        return status != null && status > 0;
    }

    public boolean isActive() {
        return getStatus().equals(TRUE);
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public List<SensorData> getData() {
        return data;
    }

    public void setData(List<SensorData> data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return objectToJson(this);
    }
}
