package com.thinkbiganalytics.nifi.provenance.repo;

import org.apache.nifi.provenance.ProvenanceEventRecord;
import org.joda.time.DateTime;

public class ProvenanceEventRecordWithId {

    private Long eventId;
    private ProvenanceEventRecord event;
    private Long timeAdded;

    public ProvenanceEventRecordWithId(Long eventId, ProvenanceEventRecord event) {
        this.eventId = eventId;
        this.event = event;
        this.timeAdded = DateTime.now().getMillis();
    }

    public Long getEventId() {
        return eventId;
    }

    public ProvenanceEventRecord getEvent() {
        return event;
    }

    public Long getTimeAdded() {
        return timeAdded;
    }

    public Long getWaitTimeMillis(){
        return DateTime.now().getMillis() - timeAdded;
    }

    public boolean isWaitingTooLong(Long maxWaitTime){
        return getWaitTimeMillis() > maxWaitTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof ProvenanceEventRecordWithId)) {
            return false;
        }

        ProvenanceEventRecordWithId that = (ProvenanceEventRecordWithId) o;

        if (eventId != null ? !eventId.equals(that.eventId) : that.eventId != null) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        return eventId != null ? eventId.hashCode() : 0;
    }
}
