package in.cdac.medinfo.csnotk.csnolib.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import in.cdac.medinfo.csnotk.csnolib.agents.SNOMEDAgent;
import in.cdac.medinfo.csnotk.csnolib.model.SimpleMapRefsetResult;
//Logs
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import in.cdac.medinfo.csnotk.csnolib.util.LoggerUtility;

public class TestSimpleMap {

	public static void main(String[] args) {
		SNOMEDAgent agent = new SNOMEDAgent();
        agent.init();
        Logger logger = LogManager.getLogger(TestSimpleMap.class);
		logger.info(LoggerUtility.CONSOLE, "Do you want to create SNOMED CT database (y/n)");
		BufferedReader serviceInput = new BufferedReader(
				new InputStreamReader(System.in));
		try {
			String dbOverride = serviceInput.readLine();
			if(dbOverride.equalsIgnoreCase("y"))
			{
				logger.info(LoggerUtility.CONSOLE, "Please Enter SNOMED CT Release file path till Snapshot");
				String snomedDirPath=serviceInput.readLine();
				agent.createSNOMEDdb(snomedDirPath, true);
			}
		} catch (IOException e1) {
			//Log the Exception
			logger.error(LoggerUtility.Exception, LoggerUtility.createErrorMessage(e1));
		}

	logger.info(LoggerUtility.CONSOLE, "Do you want to create SNOMED CT Extension database (y/n)");

		try {
			String dbOverride = serviceInput.readLine();
			if(dbOverride.equalsIgnoreCase("y"))
			{
				logger.info(LoggerUtility.CONSOLE, "Please Enter SNOMED CT Extension Release directory path till Snapshot");
				String snomedExtDirPath=serviceInput.readLine();
				agent.createExtensiondb(snomedExtDirPath, true);
			}
		} catch (IOException e1) {
			//Get the Stack trace and form the exception message.
			//Log the Exception
			logger.error(LoggerUtility.Exception, LoggerUtility.createErrorMessage(e1));
		}


		//Creation of simple map refset
		logger.info(LoggerUtility.CONSOLE, "Do you want to create Simple Map Refset database (y/n)");
		 serviceInput = new BufferedReader(
				new InputStreamReader(System.in));
		try {
			String dbOverride = serviceInput.readLine();
			if(dbOverride.equalsIgnoreCase("y"))
			{
				logger.info(LoggerUtility.CONSOLE, "Please Enter Extension Release file path till Snapshot for creation of Simple Map");
				String snomedDirPath=serviceInput.readLine();
				agent.createSimpleMapdb(snomedDirPath, true);
			}
		} catch (IOException e1) {
			//Log the Exception
			logger.error(LoggerUtility.Exception, LoggerUtility.createErrorMessage(e1));
		}
		logger.info(LoggerUtility.CONSOLE, "Do you want to get simple map from concept Id (y/n)");
		BufferedReader reteriveInput = new BufferedReader(
				new InputStreamReader(System.in));



		try {
			String dbOverride = reteriveInput.readLine();
			if(dbOverride.equalsIgnoreCase("y"))
			{


		        	logger.info(LoggerUtility.CONSOLE, "Please Enter concept Id :");
		        	String refsetComponentId=serviceInput.readLine();
		        	SimpleMapRefsetResult simpleMapRefsets=agent.searchSimpleMap(refsetComponentId);
		        	 logger.info(LoggerUtility.CONSOLE, "SimpleMapRefsetResult [conceptId={}, mapStatus={},SimpleMapRefsetGroup [" , simpleMapRefsets.getConceptId()
		     				, simpleMapRefsets.getMapStatus());
		        	 if(simpleMapRefsets.getSimpleMapRefsetGroup()!=null)
		        	 {
		        	 for (String mapTargetCode : simpleMapRefsets.getSimpleMapRefsetGroup().getSimpleMappedTargetCodes()) {
						logger.info(LoggerUtility.CONSOLE,  "{{}} " , mapTargetCode);
					}}
		        logger.info(LoggerUtility.CONSOLE, "]]");

			}
		} catch (IOException e1) {
			//Log the Exception
			logger.error(LoggerUtility.Exception, LoggerUtility.createErrorMessage(e1));
		}


	}

}
