/*
 * JsonGeneratorVisitor.java
 *
 */

package de.uni_stuttgart.vis.vowl.owl2vowl.export;

import de.uni_stuttgart.vis.vowl.owl2vowl.constants.Standard_Iris;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.VowlData;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.nodes.classes.VowlClass;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.nodes.classes.VowlThing;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.nodes.datatypes.VowlDatatype;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.nodes.datatypes.VowlLiteral;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.properties.VowlDatatypeProperty;
import de.uni_stuttgart.vis.vowl.owl2vowl.model.properties.VowlObjectProperty;

import java.util.*;

/**
 *
 */
public class JsonGeneratorVisitorImpl implements JsonGeneratorVisitor {
	private final VowlData vowlData;
	private final Map<String, Object> root;
	private Map<String, Object> header;
	private Map<String, Object> metrics;
	private List<Object> _class;
	private List<Object> classAttribute;
	private List<Object> datatype;
	private List<Object> datatypeAttribute;
	private List<Object> objectProperty;
	private List<Object> objectPropertyAttribute;

	public JsonGeneratorVisitorImpl(VowlData vowlData, Map<String, Object> root) {
		this.vowlData = vowlData;
		this.root = root;
		populateJsonRoot();
	}

	protected void populateJsonRoot() {
		header = new LinkedHashMap<>();
		metrics = new LinkedHashMap<>();
		_class = new ArrayList<>();
		classAttribute = new ArrayList<>();
		datatype = new ArrayList<>();
		datatypeAttribute = new ArrayList<>();
		objectProperty = new ArrayList<>();
		objectPropertyAttribute = new ArrayList<>();

		root.put("header", header);
		root.put("metrics", metrics);
		root.put("class", _class);
		root.put("classAttribute", classAttribute);
		root.put("datatype", datatype);
		root.put("datatypeAttribute", datatypeAttribute);
		root.put("property", objectProperty);
		root.put("propertyAttribute", objectPropertyAttribute);
	}

	@Override
	public void visit(VowlThing vowlThing) {
		Map<String, Object> thingObject = new HashMap<>();
		thingObject.put("id", vowlData.getIdForEntity(vowlThing));
		thingObject.put("type", vowlThing.getType());

		_class.add(thingObject);

		Map<String, Object> thingAttributeObject = new HashMap<>();

		// TODO
		thingAttributeObject.put("id", vowlData.getIdForEntity(vowlThing));
		thingAttributeObject.put("label", 0);
		thingAttributeObject.put("iri", Standard_Iris.OWL_THING_CLASS_URI);

		classAttribute.add(thingAttributeObject);
	}

	@Override
	public void visit(VowlClass vowlClass) {
		Map<String, Object> classObject = new HashMap<>();
		classObject.put("id", vowlData.getIdForEntity(vowlClass));
		classObject.put("type", vowlClass.getType());

		_class.add(classObject);

		Map<String, Object> classAttributeObject = new HashMap<>();

		// TODO
		classAttributeObject.put("id", vowlData.getIdForEntity(vowlClass));
		classAttributeObject.put("label", 0);
		classAttributeObject.put("iri", vowlClass.getIri().toString());
		classAttributeObject.put("comment", 0);
		classAttributeObject.put("isDefinedBy", 0);
		classAttributeObject.put("owlVersion", 0);
		classAttributeObject.put("attributes", 0);
		classAttributeObject.put("subClasses", 0);
		classAttributeObject.put("superClasses", 0);
		classAttributeObject.put("annotations", 0);

		classAttribute.add(classAttributeObject);
	}

	@Override
	public void visit(VowlLiteral vowlLiteral) {
		// TODO
	}

	@Override
	public void visit(VowlDatatype vowlDatatype) {
		// TODO
	}

	@Override
	public void visit(VowlObjectProperty vowlObjectProperty) {
		// TODO
	}

	@Override
	public void visit(VowlDatatypeProperty vowlDatatypeProperty) {
		// TODO
	}
}

@@ -675,27 +675,104 @@
 ty;%0A
-%0Aimport java.util.*
+import org.semanticweb.owlapi.model.IRI;%0A%0Aimport java.util.*;%0Aimport java.util.stream.Collectors
 ;%0A%0A/
@@ -3396,16 +3396,287 @@
 ns%22, 0);
+%0A%09%09classAttributeObject.put(%22union%22, getListWithIds(vowlClass.getElementsOfUnion()));%0A%09%09classAttributeObject.put(%22intersection%22, getListWithIds(vowlClass.getElementOfIntersection()));%0A%09%09// TODO can a complement not be a list?%0A%09%09//lassAttributeObject.put(%22complement%22, 0);
 %0A%0A%09%09clas
@@ -4033,11 +4033,224 @@
  TODO%0A%09%7D
+%0A%0A%09protected List%3CString%3E getListWithIds(Collection%3CIRI%3E iriList) %7B%0A%09%09List%3CString%3E idList = iriList.stream().map(iri -%3E String.valueOf(vowlData.getIdForIri(iri))).collect(Collectors.toList());%0A%0A%09%09return idList;%0A%09%7D
 %0A%7D%0A

Add export of union and intersection for json.