package cz.senslog.analytics.domain;


import java.util.Objects;

public record Sensor(long id, long unitId, long sensorId, long groupId) {

    public static Sensor empty() {
        return new Sensor(-1, -1, -1, -1);
    }

    public Sensor(long unitId, long  sensorId) {
        this(-1, unitId, sensorId, -1);
    }

    public Sensor(long id, long unitId, long  sensorId) {
        this(id, unitId, sensorId, -1);
    }

    public Sensor(Sensor sensor, long groupId) {
        this(sensor.id(), sensor.unitId(), sensor.sensorId(), groupId);
    }

    public boolean isEmpty() {
        return this.equals(empty());
    }

    public boolean isNotEmpty() {
        return !isEmpty();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Sensor sensor = (Sensor) o;
        return unitId == sensor.unitId &&
                sensorId == sensor.sensorId;
    }

    @Override
    public int hashCode() {
        return Objects.hash(unitId, sensorId);
    }

    @Override
    public String toString() {
        return String.format("[%d] %d-%d", id, unitId, sensorId);
    }
}
