package br.uem.din.architectureEvolution;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import br.uem.din.architectureEvolution.representation.Architecture;
import br.uem.din.architectureEvolution.representation.Class;
import br.uem.din.architectureEvolution.representation.Component;
import br.uem.din.architectureEvolution.representation.InterElementRelationship;
import br.uem.din.metrics.concernDrivenMetrics.concernCohesion.LCC;
import br.uem.din.metrics.concernDrivenMetrics.concernCohesion.LCCComponentResult;
import br.uem.din.metrics.concernDrivenMetrics.concernDiffusion.CDAC;
import br.uem.din.metrics.concernDrivenMetrics.concernDiffusion.CDAI;
import br.uem.din.metrics.concernDrivenMetrics.concernDiffusion.CDAO;
import br.uem.din.metrics.concernDrivenMetrics.concernDiffusion.ConcernDiffusionMetric;
import br.uem.din.metrics.concernDrivenMetrics.interactionBeteweenConcerns.CIBC;
import br.uem.din.metrics.concernDrivenMetrics.interactionBeteweenConcerns.CIBCResult;
import br.uem.din.metrics.concernDrivenMetrics.interactionBeteweenConcerns.IIBC;
import br.uem.din.metrics.concernDrivenMetrics.interactionBeteweenConcerns.IIBCResult;
import br.uem.din.metrics.concernDrivenMetrics.interactionBeteweenConcerns.OOBC;
import br.uem.din.metrics.concernDrivenMetrics.interactionBeteweenConcerns.OOBCResult;

public class Main {
		
	public static void main(String[] args) throws Exception {
		BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
		
		System.out.println("Enter the path of the xmi file: ");
		String xmiFilePath = buffer.readLine();
				
		Architecture architecture1 = new Architecture(xmiFilePath);
		calculateMetrics(architecture1);
		
		System.out.println();
		System.out.println("-------------------------------------------------------");
		System.out.println();
		
		Architecture architecture2 = architecture1.deepClone();
		for (Component comp : architecture2.getComponents().values()) {
			comp.addConcern("Teste");
			for (Class c : comp.getClasses().values()) {
				c.createAttribute("asdfg", "String");
				break;
			}
		}
		
		for (InterElementRelationship relationship : architecture2.getInterElementRelationships()) {
			architecture2.removeInterElementComponentRelationship(relationship);
			break;
		}
		
//		architecture2.save("C:\\Dojo\\", 2);
		architecture2.save();
		
		calculateMetrics(architecture2);
	}

	private static void calculateMetrics(Architecture architecture) {
		System.out.println("LCC");
		
		LCC result = new LCC(architecture);
		for (LCCComponentResult component : result.getResults()) {
			System.out.println(component.toString());
		}
		
		System.out.println("CDAC");
		
		printConcernDiffusionResult(new CDAC(architecture));
		
		System.out.println("CDAI");
		
		printConcernDiffusionResult(new CDAI(architecture));
		
		System.out.println("CDAO");
		
		printConcernDiffusionResult(new CDAO(architecture));
		
		System.out.println("CIBC");
		
		CIBC cibc = new CIBC(architecture);
		for (CIBCResult c : cibc.getResults().values()) {
			System.out.println(c.toString());
		}
		
		System.out.println("IIBC");
		
		IIBC iibc = new IIBC(architecture);
		for (IIBCResult c : iibc.getResults().values()) {
			System.out.println(c.toString());
		}
		
		System.out.println("OOBC");
		
		OOBC oobc = new OOBC(architecture);
		for (OOBCResult c : oobc.getResults().values()) {
			System.out.println(c.toString());
		}
	}

	private static <T> void printConcernDiffusionResult(ConcernDiffusionMetric<T> cdac) {
		for (T c : cdac.getResults()) {
			System.out.println(c.toString());
		}
	}
}
