package semantic.controler;

import semantic.model.DoItYourselfModel;
import semantic.model.IModelFunctions;
import semantic.model.ObservationEntity;
import semantic.model.SemanticModel;
import semantic.view.JSONEndpoint;

import java.io.IOException;
import java.util.List;

public class Controller {
	private final SemanticModel model;
	private final IModelFunctions customModel;
	private final IControlFunctions customControl;

	public Controller() {
		this.model = new SemanticModel("tp-iss.ttl");
		this.customModel = new DoItYourselfModel(this.model);
		this.customControl = new DoItYourselfControl(this.model, this.customModel);
		this.initializeContext();
	}

	public static void main(String[] args) {
		Controller controller = new Controller();
		try {
			List<ObservationEntity> obsList = JSONEndpoint.parseObservations("tempm.txt");
			String tempURI = controller.model.getEntityURI("Temperature").get(0);
			controller.getCustomControl().instantiateObservations(obsList, tempURI);
			obsList = JSONEndpoint.parseObservations("hum.txt");
			String humidityURI = controller.model.getEntityURI("Humidity").get(0);
			controller.getCustomControl().instantiateObservations(obsList, humidityURI);
			controller.exportModel("export.ttl");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private void initializeContext() {
		this.customModel.createPlace("Aarhus");
	}

	public void exportModel(String path) {
		this.model.exportModel(path);
	}

	public SemanticModel getModel() {
		return this.model;
	}

	public IModelFunctions getCustomModel() {
		return this.customModel;
	}

	public IControlFunctions getCustomControl() {
		return this.customControl;
	}
}
