package net.heartshield.data;

import com.google.gson.annotations.SerializedName;

/**
 * Measurement information displayed in ResultListActivity and cached for performance.
 *
 * @author David Madl (git@abanbytes.eu)
 * @date 2017-04-20
 */
public class MeasurementSummary {
    /** start time of the measurement in UTC seconds since the Unix epoch (Unix timestamp) */
    public long startTime;

    /** globally unique identifier of the client app */
    public String appId;

    /** local number of the measurement (only valid on the same device) */
    public int number;

    /** whether the measurement was sent, and whether classification itself was successful (else unclassified) */
    public Status status;

    /** risk level 0-3: 0 is unknown, 1-3 is low, medium, high */
    public int riskLevel;

    /** score in range 0-100: confidence that coronary artery disease is present (probability score in [0,1]) */
    public int heartScore;

    /** beats per minute */
    public int bpm;

    /** whether audioData was successfully transmitted */
    public boolean audioSynced;

    /** whether this Measurement should be transmitted to the server */
    public boolean dirty;

    public MeasurementSummary() {}

    public MeasurementSummary(long startTime, String appId, Status status, int riskLevel, int heartScore, int bpm, boolean audioSynced, boolean dirty) {
        this.startTime = startTime;
        this.appId = appId;
        //this.number = number;
        this.number = 0;
        this.status = status;
        this.riskLevel = riskLevel;
        this.heartScore = heartScore;
        this.bpm = bpm;
        this.audioSynced = audioSynced;
        this.dirty = dirty;
    }

    public MeasurementId getId() {
        return new MeasurementId(appId, startTime);
    }

    /** @return false if this Measurement needs to be transferred to the server. */
    public boolean isSynced() {
        return status != Status.OFFLINE && audioSynced && !dirty;
    }

    @Override
    public boolean equals(Object obj) {
        if(obj == null)
            return false;
        if(!(obj instanceof MeasurementSummary))
            return false;
        MeasurementSummary other = (MeasurementSummary) obj;
        return getId().equals(other.getId());
    }

    public enum Status {
        OK,
        UNCLASSIFIED,
        OFFLINE
    }
}
