package ua.be.wee.model;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import ua.be.wee.model.nodes.Activity;
import ua.be.wee.model.nodes.Artifact;
import ua.be.wee.model.nodes.ports.ControlInputPort;
import ua.be.wee.model.nodes.ports.ControlOutputPort;
import ua.be.wee.model.pm.PM;
import ua.be.wee.model.pt.Event;
import ua.be.wee.model.pt.PT;
import ua.be.wee.model.pt.TraceArtifact;
import ua.be.wee.model.repository.NodeRespository;
import ua.be.wee.model.repository.PMRepository;
import ua.be.wee.model.repository.PTRepository;
import ua.be.wee.model.util.Pair;

@Component
public class EnactmentController {

	@Autowired
	private PMRepository pmRepo;
	
	@Autowired
	private NodeRespository nodeRepo;
	
	@Autowired
	private PTRepository traceRepo;
	
	public List<PM> getAllPMs() {
		return pmRepo.getAllPMs();
	}

	public PM getPM(String pmid) throws Exception {
		PM pm = pmRepo.getPM(pmid);
		pm.setNodes(nodeRepo.getNodes(pm.getIri()));
		return pm;
	}

	public List<Pair<String,String>> findNextNodes(String iri) {
		return pmRepo.findNextNodes(iri); 
	}

	public PT createTrace(PM pm) throws Exception {
		return traceRepo.createTrace(pm);
	}

	public void addStartEvent(PT pt, ControlInputPort port, Activity act, List<TraceArtifact> arts) throws Exception {
		traceRepo.createStartEvent(pt,port,act,arts);
	}

	public void addEndEvent(PT pt, List<TraceArtifact> arts, ControlOutputPort p) throws Exception {
		traceRepo.createEndEvent(pt,arts,p);	
	}

	public Event addEndTraceEvent(String iri, String previous, String pmIRI) throws Exception {
		return traceRepo.createEndTraceEvent(iri,previous, pmIRI);
		
	}

	public void updatePT(PT pt) throws Exception {
		traceRepo.updatePT(pt);
		
	}
}
