package gov.va.med.mpn;


import static org.junit.Assert.*;
import gov.va.med.mpn.dao.interfaces.CategoryDAO;
import gov.va.med.mpn.dao.interfaces.ClassificationDAO;
import gov.va.med.mpn.dao.interfaces.CodedControlDataDAO;
import gov.va.med.mpn.entity.pojo.Category;
import gov.va.med.mpn.entity.pojo.Classification;
import gov.va.med.mpn.entity.pojo.CodedControlData;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import javax.persistence.NoResultException;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

public class CodedControlDataTest extends AbstractTestDAO {
	@Autowired
	protected CodedControlDataDAO codedControlDataDao;
	
	@Autowired
	protected ClassificationDAO classificationDao;
	
	@Autowired
	protected CategoryDAO categoryDao;
	

	  /** The slf4j logger. */
	private final Logger slf4jLogger = LoggerFactory.getLogger(CodedControlDataTest.class);
	
	@Test
	public void findCodedControlData(){
		
		List<CodedControlData> names = codedControlDataDao.findAll();
		CodedControlData codeControl = names.get(0);
		slf4jLogger.debug("Control Name:"+codeControl.getControlName());
		Category category = codeControl.getCategory();
		slf4jLogger.debug("Category Name:"+category.getCategoryName());
		Classification classification = codeControl.getClassification();
		slf4jLogger.debug("Class Name:"+classification.getClassName());
		assertEquals("UUID Match","B19EFE42-339A-47C8-AC6B-00106B58542B",codeControl.getUuid());
		
	}
	

	
	@Test
	public void findSingleCodedControlData(){
		
		CodedControlData codedControlData = codedControlDataDao.findAllWithUUID("EB2BCA45-6216-4789-BDC6-0583532B59AF");
		slf4jLogger.debug("Control Name:"+codedControlData.getControlName());
		assertEquals("Control Name","Tonometry method used - Tonometry",codedControlData.getControlName());
		
		
	}	
	
	@Test
	public void findCodedControlDataOnName(){
		
		List<CodedControlData> names = codedControlDataDao.findCodedControlDataWithControlName("Physical Exam - Ear Canal");
		slf4jLogger.debug("Control Name:"+names.size());
		String controlName = null;
		
		for (CodedControlData codedControlData : names) {
			if (codedControlData.getControlName().equals("Physical Exam - Ear Canal")){
				controlName = codedControlData.getControlName();
			}
		}
		
		assertEquals("findCodedControlDataOnName: control Name","Physical Exam - Ear Canal",controlName);
		
	}
	
	
	@Test
	public void findCodedControlDataWithClassId(){
		
		List<CodedControlData> names = codedControlDataDao.findCodedControlDataWithClassId(10);
		slf4jLogger.debug("Control Name:"+names.size());
		String controlName = null;
		
		for (CodedControlData codedControlData : names) {
			if (codedControlData.getControlName().equals("Mental Disorder 2 - Indicate axis category")){
				controlName = codedControlData.getControlName();
			}
		}
		
		assertEquals("findCodedControlDataWithClassId: control Name","Mental Disorder 2 - Indicate axis category",controlName);
		
	}
	
	@Test
	public void findCodedControlDataWithCatrgoryId(){
		
		try{
			List<CodedControlData> names = codedControlDataDao.findCodedControlDataWithCategoryId(4);
			slf4jLogger.debug("Control Name:"+names.size());
			String controlName = null;
			
			for (CodedControlData codedControlData : names) {
				if (codedControlData.getControlName().equals("Diagnosis of Menieres syndrome or endolymphatic hydrops")){
					controlName = codedControlData.getControlName();
				}
			}
			
			assertEquals("findCodedControlDataWithCatrgoryId: control Name","Diagnosis of Menieres syndrome or endolymphatic hydrops",controlName);

		}
		catch (NoResultException  ex)
		{
			slf4jLogger.debug("findCodedControlDataWithCatrgoryId: No data Found");
		}
				
	}
	
	@Test
	public void findCodedControlDataWithCategoryIdAndName(){
		
		List<CodedControlData> names = codedControlDataDao.findCodedControlDataWithCategoryIdAndName(4,"Eye");
		slf4jLogger.debug("Control Name:"+names.size());
		String uuid = null;
		
		for (CodedControlData codedControlData : names) {
			if (codedControlData.getUuid().equals("510C07D9-2AD5-4C6E-AF17-BA229185601C")){
				uuid = codedControlData.getUuid();
			}
		}
		
		assertEquals("findCodedControlDataWithCategoryIdAndName: uuid","510C07D9-2AD5-4C6E-AF17-BA229185601C",uuid);
	}
	
	@Test
	public void findCodedControlDataWithClassificationIdAndName(){
		
		List<CodedControlData> names = codedControlDataDao.findCodedControlDataWithClassificationIdAndName(10,"Eye");
		slf4jLogger.debug("Control Name:"+names.size());
		String uuid = null;
		
		for (CodedControlData codedControlData : names) {
			if (codedControlData.getUuid().equals("ED416E45-6530-4D92-A64C-56ADDF56252B")){
				uuid = codedControlData.getUuid();
			}
		}
		
		assertEquals("findCodedControlDataWithClassificationIdAndName: uuid","ED416E45-6530-4D92-A64C-56ADDF56252B",uuid);
	}	
	
	@Test
	public void findCodedControlDataWithClassificationIdAndCategoryIdAndName(){
		
		List<CodedControlData> names = codedControlDataDao.findCodedControlDataWithClassificationIdAndCategoryIdAndName(10,4,"Eye");
		slf4jLogger.debug("Control Name:"+names.size());
		String uuid = null;
		
		for (CodedControlData codedControlData : names) {
			if (codedControlData.getUuid().equals("E85DD5BE-ACF7-43E3-8B87-FF1556A980CE")){
				uuid = codedControlData.getUuid();
			}
		}
		assertEquals("findCodedControlDataWithClassificationIdAndCategoryIdAndName: uuid","E85DD5BE-ACF7-43E3-8B87-FF1556A980CE",uuid);
	}	
	
	/*@Test
	public void insertCodedControlData(){
		

		CodedControlData codedControlData = new CodedControlData();
		codedControlData.setControlName("MPNInsert Test");
		codedControlData.setUuid(UUID.randomUUID().toString());
		codedControlData.setCreatedBy("MPNAdmin");
		Date dt = new Date();
		codedControlData.setDateCreated(dt);
		codedControlData.setDescription("MPNAdmin insert test");
		codedControlData.setValid(true);
		
		List<Classification> classif1 = classificationDao.findAll();
		slf4jLogger.debug("classif1 size Name:"+classif1.size());
		Classification classification = classif1.get(0);
		
		List<Category> categoryList = categoryDao.findAll();
		slf4jLogger.debug("category list size Name:"+categoryList.size());
		Category category = categoryList.get(0);
		
		codedControlData.setCategory(category);
		codedControlData.setClassification(classification);
		
		codedControlDataDao.persist(codedControlData);
		
		
				
		List<CodedControlData> names = codedControlDataDao.findCodedControlDataWithControlName("MPNInsert Test");
		slf4jLogger.debug("Control Name:"+names.size());
		String controlName = null;
		
		for (CodedControlData codedControlRowData : names) {
			if (codedControlRowData.getControlName().equals("MPNInsert Test")){
				controlName = codedControlData.getControlName();
			}
		}
		
		slf4jLogger.debug("controlName Name:"+controlName);
		assertEquals("insertCodedControlData: control Name","MPNInsert Test",controlName);
		
		
	}*/
	
}