package ua.be.wee.model.pt;

import java.sql.Timestamp;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;

import ua.be.wee.model.nodes.Artifact;

@Entity
public class TraceArtifact {
	
	private String location;
	
	private String tag;
	
	private String GUID;
	
	@Id
	private String iri;
	
	@OneToOne
	private StartActivityEvent consumedBy;
	
	@OneToOne
	private EndActivityEvent producedBy;
	
	@OneToOne
	private Artifact relatesTo;
	
	private Timestamp timestamp;
	
	@OneToOne
	private TraceArtifact nextVersion;
	
	
	public Timestamp getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(Timestamp timestamp) {
		this.timestamp = timestamp;
	}
	
	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public String getTag() {
		return tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	}

	public String getGUID() {
		return GUID;
	}

	public void setGUID(String gUID) {
		GUID = gUID;
	}

	public String getIri() {
		return iri;
	}

	public void setIri(String iri) {
		this.iri = iri;
	}

	public StartActivityEvent getConsumedBy() {
		return consumedBy;
	}

	public void setConsumedBy(StartActivityEvent consumedBy) {
		this.consumedBy = consumedBy;
	}

	public EndActivityEvent getProducedBy() {
		return producedBy;
	}

	public void setProducedBy(EndActivityEvent producedBy) {
		this.producedBy = producedBy;
	}

	public Artifact getRelatesTo() {
		return relatesTo;
	}

	public void setRelatesTo(Artifact relatesTo) {
		this.relatesTo = relatesTo;
	}

	public TraceArtifact getNextVersion() {
		return nextVersion;
	}

	public void setNextVersion(TraceArtifact nextVersion) {
		this.nextVersion = nextVersion;
	}
	
	public String getFileExtension() {
		if (location != null && !location.equals("")) {
			String ext = location.substring(location.lastIndexOf(".")+1);
			return ext;
		}
		return null;
	}
	
	@Override
	public boolean equals(Object obj) {
		return iri.equals(((TraceArtifact)obj).getIri());
	}
}
