// Copyright (c) 2020 UWB & LESP.
// The UWB & LESP license this file to you under the MIT license.

package cz.senslog.connector.model.v1;

import java.util.*;

public class UnitInfo {

    private String description;
    private Integer holderId;
    private Long unitId;

    Map<Long, SensorInfo> sensors;

    public UnitInfo() {
        this.sensors = new HashMap<>();
    }

    public String getDescription() {
        return description;
    }

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

    public Integer getHolderId() {
        return holderId;
    }

    public void setHolderId(Integer holderId) {
        this.holderId = holderId;
    }

    public Long getUnitId() {
        return unitId;
    }

    public void setUnitId(Long unitId) {
        this.unitId = unitId;
    }

    public Collection<SensorInfo> getSensors() {
        return sensors.values();
    }

    public SensorInfo getSensor(long id) {
        return sensors.get(id);
    }

    public void setSensors(List<SensorInfo> sensorInfos) {
        sensorInfos.forEach(s -> this.sensors.putIfAbsent(s.getSensorId(), s));
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        UnitInfo unitInfo = (UnitInfo) o;
        return Objects.equals(unitId, unitInfo.unitId);
    }

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