package cz.muni.fi.lasaris.sbms.data.providers.bacnet;

import java.time.LocalDateTime;

import cz.muni.fi.lasaris.sbms.data.entities.values.RawValue;

public class CachedValue  {
	
	private RawValue value;
	
	private LocalDateTime timestamp;

	public LocalDateTime getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(LocalDateTime timestamp) {
		this.timestamp = timestamp;
	}

	public RawValue getValue() {
		return value;
	}

	public void setValue(RawValue value) {
		this.value = value;
		this.timestamp = LocalDateTime.now();
	}
	
	public void setValue(RawValue value, LocalDateTime timestamp) {
		this.value = value;
		this.timestamp = timestamp;
	}
	
	public CachedValue(RawValue value) {
		this.value = value;
		this.timestamp = LocalDateTime.now();
	}
	
	public boolean isValid(long validity) {
		return LocalDateTime.now().isBefore(this.timestamp.plusSeconds(validity));
	}
}
