package ua.be.wee.model.pm;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;

import ua.be.wee.model.nodes.InitialNode;
import ua.be.wee.model.nodes.Node;

@Entity
public class PM {
	
	@Id
	private String iri;
	
	private String name;
	
	@OneToMany
	private List<Node> nodes;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getIri() {
		return iri;
	}

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

	public List<Node> getNodes() {
		return nodes;
	}

	public void setNodes(List<Node> nodes) {
		this.nodes = nodes;
	}

	public String toString() {
		return name;
	}
	
	public InitialNode getInitial() {
		if (nodes != null) {
			for (Node node : nodes) {
				if (node instanceof InitialNode) {
					return (InitialNode) node;
				}
			}
		} 
		return null;
		
	}
	
	public Node getNode(String iri) {
		if (nodes != null) {
			for (Node node : nodes) {
				if (node.getIri().equals(iri)) {
					return node;
				}
			}			
		}
		return null;
	}

}
