package ua.be.wee.controller.rest;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import ua.be.wee.model.pt.Event;
import ua.be.wee.model.pt.StartTraceEvent;
import ua.be.wee.model.repository.FusekiWrapper;
import ua.be.wee.model.repository.PTRepository;

@RestController
public class PTController {

	@Autowired
	private PTRepository ptRepository;
	
	
	@Autowired
	public PTController(@Value("${endpoint}")final String endpoint) throws Exception {
		if (FusekiWrapper.getInstance().getServiceURI() == null) {
			FusekiWrapper.getInstance().setServiceURI(endpoint);
		}
	} 
			
	@CrossOrigin
	@GetMapping("/traces")
	public List<StartTraceEvent> allPTs() throws Exception {
		return ptRepository.getStartTraceEvents();
	}
	
	@CrossOrigin
	@GetMapping("/traces/events/{traceiri}")
	public List<Event> getEvents(@PathVariable String traceiri) throws Exception {
		return ptRepository.getEvents(traceiri);
	}
	
	@CrossOrigin
	@GetMapping("/traces/active/{pmiri}")
	public List<StartTraceEvent> getActiveTraces(@PathVariable String pmiri) throws Exception {
		return ptRepository.getActiveTraces(pmiri);
	}
	
	@CrossOrigin
	@GetMapping("/traces/finished/{pmiri}")
	public List<StartTraceEvent> getConcludedTraces(@PathVariable String pmiri) throws Exception {
		return ptRepository.getConcludedTraces(pmiri);
	}
	


	
}
