package gov.va.med.esr.service;

import gov.va.med.esr.common.infra.ImpreciseDate;
import gov.va.med.esr.common.infra.ImpreciseDateUtils;
import gov.va.med.esr.common.model.ee.VerificationInfo;
import gov.va.med.esr.common.model.financials.FinancialStatement;
import gov.va.med.esr.common.model.financials.SpouseFinancials;
import gov.va.med.esr.common.model.insurance.Medicare;
import gov.va.med.esr.common.model.lookup.AACIndicator;
import gov.va.med.esr.common.model.lookup.AddressType;
import gov.va.med.esr.common.model.lookup.AuthenticationLevel;
import gov.va.med.esr.common.model.lookup.Country;
import gov.va.med.esr.common.model.lookup.EmploymentStatus;
import gov.va.med.esr.common.model.lookup.EnrollmentPriorityGroup;
import gov.va.med.esr.common.model.lookup.Gender;
import gov.va.med.esr.common.model.lookup.MessageType;
import gov.va.med.esr.common.model.lookup.NameType;
import gov.va.med.esr.common.model.lookup.SSNType;
import gov.va.med.esr.common.model.lookup.VAFacility;
import gov.va.med.esr.common.model.lookup.VOAApplicationStatus;
import gov.va.med.esr.common.model.lookup.VOAFormType;
import gov.va.med.esr.common.model.lookup.VeteranIdentifierType;
import gov.va.med.esr.common.model.person.Person;
import gov.va.med.esr.common.model.person.PreferredFacility;
import gov.va.med.esr.common.model.person.SSN;
import gov.va.med.esr.common.model.person.Spouse;
import gov.va.med.esr.common.model.person.VOAApplication;
import gov.va.med.esr.common.model.person.id.PersonIdEntityKeyImpl;
import gov.va.med.esr.common.model.person.id.VPIDEntityKeyImpl;
import gov.va.med.esr.common.rule.parameter.EmploymentInputParameter;
import gov.va.med.esr.common.util.RuleAbstractTestCase;
import gov.va.med.esr.service.impl.VOAApplicationServiceImpl;
import gov.va.med.fw.rule.SimpleRuleMethod;
import gov.va.med.ps.model.PersonVPID;


import java.math.BigDecimal;
import java.net.URLEncoder;
import java.net.URLDecoder;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
public class VOAProcessClinicalDterminationsTest extends RuleAbstractTestCase {

	public VOAProcessClinicalDterminationsTest(String arg0) {
		super(arg0);
	}
	
//	
//	public void testMSTNewPerson() throws Exception {
//		
//		//VAFacility.CODE_MHV
//		VAFacility fac = this.getLookupService().getVaFacilityByCode(VAFacility.CODE_MHV.getCode());
//		String vpid ="1008590759V367283";
//
//		Person onFile = this.doBuildSimplePerson(true, vpid, null);
//		onFile.setVOA(true);
//		
////		Person onFile = this.buildSimplePerson();
//
//		Person incoming = this.savePerson(onFile);
//
//		//add simple  Perm address "Clairmont Dr, Atlanta,GA 30305"
//		//with now as updatedDate and null endDate */
//		this.addPermanentAddress(incoming, Calendar.getInstance().getTime(),null);
//		incoming.getPermanentAddress().setLine2("Address Line 2");
//		incoming.getPermanentAddress().setLine3("Address Line 3");
//		incoming.getPermanentAddress().setCountry(null);
//		
//		VerificationInfo vi = new VerificationInfo("x",	MessageType.CODE_ORUZ07_TO_ESR.getCode(), "x");
////		vi.setSiteNumber(incoming.getEligibilityVerification().getVerificationFacility().getCode());
//		Person updated = this.getMessagingService().processVOA(incoming, onFile, fac,vi);
//		
//		assertEquals("CLAIRMONT DR", updated.getPermanentAddress().getLine1());
//		assertEquals("ADDRESS LINE 2", updated.getPermanentAddress().getLine2());
//		assertEquals( "ADDRESS LINE 3", updated.getPermanentAddress().getLine3());
//		//5.5.1.	SUC2031.17.1 - Permanent Address Country Not Required
//		assertEquals(Country.CODE_USA.getName(), updated.getPermanentAddress().getCountry()); //if null, default to United States
//	}	
//	
//	public void testProcessAddressNullLine2To3() throws Exception {
//		
//		//VAFacility.CODE_MHV
//		VAFacility fac = this.getLookupService().getVaFacilityByCode(VAFacility.CODE_MHV.getCode());
//		String vpid ="1008590759V367283";
//
//		Person onFile = this.doBuildSimplePerson(true, vpid, null);
//
//		Person incoming = this.savePerson(onFile);
//
//		//add simple  Perm address "Clairmont Dr, Atlanta,GA 30305"
//		//with now as updatedDate and null endDate */
//		this.addPermanentAddress(incoming, Calendar.getInstance().getTime(),null);
//		//5.4.1.	SUC2031.16.1 - Permanent Street Address Line 2 Not Required
//		//5.4.2.	SUC2031.16.2 - Permanent Street Address Line 3 Not Required
//		incoming.getPermanentAddress().setLine2(null);
//		incoming.getPermanentAddress().setLine3(null);
//		incoming.getPermanentAddress().setCountry(Country.CODE_PHILIPPINES.getName());
//		
//		
//		VerificationInfo vi = new VerificationInfo("x",	MessageType.CODE_ORUZ07_TO_ESR.getCode(), "x");
//		Person updated = this.getMessagingService().processVOA(incoming, onFile, fac,vi);
//
//		assertEquals(Country.CODE_PHILIPPINES.getName(), updated.getPermanentAddress().getCountry()); //if null, default to United States
//		assertEquals("CLAIRMONT DR", updated.getPermanentAddress().getLine1());
//		assertEquals(null, updated.getPermanentAddress().getLine2());
//		assertEquals(null, updated.getPermanentAddress().getLine3());
//	}	
//	
//	//4.2.1.1	SUC2031.3.2.1 - [1469] Process Person Address Data Decision Table
//	public void testProcessAddressDecisionTable_ruleN()
//	{
//		return;
//	}	
//	
//	public void testPendingStatePCE() throws Exception
//	{
//		//NOTE: after this is run successfully, the record is no longer new to ES 
//		//since 200ESR correlaiton will be added. Need to find another record wo/ 200ESR Correlation
//		
//		Person incoming = new Person();
//		VOAApplication voaApp = createDefaultVOAApplicationAndPerson("1606118356", new Date(10,0,1), "JAL-GGCD", null, "UU-UNRESPONSIVE", "M", "796121910", incoming );
//		this.getVoaApplicationService().save(voaApp);
//		this.setComplete();
//		
//		BigDecimal appId = (BigDecimal) voaApp.getEntityKey().getKeyValue();
//		this.getVoaApplicationService().processVoaApplication(appId, incoming);
//
//	}
//	
//	public void testProcessNewPerson() throws Exception
//	{
//		//NOTE: after this is run successfully, the record is no longer new to ES 
//		//since 200ESR correlaiton will be added. Need to find another record wo/ 200ESR Correlation
//		
//		Person incoming = new Person();
//		VOAApplication voaApp = createDefaultVOAApplicationAndPerson("1005123867", new Date(53,6,15), "NATHAN", "EUGENE", "DOUGLAS", "M", "796121912", incoming );
//		
//        PreferredFacility pf = voaApp.getPreferredFacility();
//        if(pf == null) pf = new PreferredFacility();
//        
//        VAFacility vaf = (VAFacility) this.getLookupService().getVaFacilityByStationNumber("742");
//
//        pf.setFacility(vaf);
//        voaApp.setPreferredFacility(pf);
//
//		
//		this.getVoaApplicationService().save(voaApp);
//		this.setComplete();
//		
////		BigDecimal appId = (BigDecimal) voaApp.getEntityKey().getKeyValue();
////		this.getVoaApplicationService().processVoaApplication(appId, incoming);
//
//	}
//	
//	public void testInsuranceMedicareA() throws Exception
//	{
//		//NOTE: after this is run successfully, the record is no longer new to ES 
//		//since 200ESR correlaiton will be added. Need to find another record wo/ 200ESR Correlation
//		
//		Person incoming = new Person();
//		VOAApplication voaApp = createDefaultVOAApplicationAndPerson("1606118356", new Date(10,0,1), "JAL-GGCD", null, "UU-UNRESPONSIVE", "M", "796121910", incoming );
//		
//		//attach a Medicare A
//		this.attachMedicare(incoming);
//		Medicare medA = (Medicare)incoming.getMedicareInsurances().iterator().next();
//		medA.setEnrolledInPartA(Boolean.TRUE);
//		medA.setEnrolledInPartB(Boolean.FALSE);
//		
//		//using existing appID already created by other test cases
//		BigDecimal appId = new BigDecimal("375345548");
////		this.getVoaApplicationService().processVoaApplication(appId, incoming);
//		this.getVoaApplicationService().forwardVOAApplication(appId, incoming);
//
//	}
//	
//	public void testInsuranceMedicareAB() throws Exception
//	{
//		//NOTE: after this is run successfully, the record is no longer new to ES 
//		//since 200ESR correlaiton will be added. Need to find another record wo/ 200ESR Correlation
//		
//		Person incoming = new Person();
//		VOAApplication voaApp = createDefaultVOAApplicationAndPerson("1606118356", new Date(10,0,1), "JAL-GGCD", null, "UU-UNRESPONSIVE", "M", "796121910", incoming );
//		
//		//attach a Medicare A, then B
//		this.attachMedicare(incoming);
//		this.attachMedicare(incoming);
//		
//		Iterator it = incoming.getMedicareInsurances().iterator();
//		Medicare medA = (Medicare)it.next();
//		medA.setEnrolledInPartA(Boolean.TRUE);
//		medA.setEnrolledInPartB(Boolean.FALSE);
//		
//		Medicare medB = (Medicare)it.next();
//		medA.setEnrolledInPartA(Boolean.FALSE);
//		medA.setEnrolledInPartB(Boolean.TRUE);
//		
//		//using existing appID already created by other test cases
//		BigDecimal appId = new BigDecimal("375345548");
//		this.getVoaApplicationService().processVoaApplication(appId, incoming);
//
//	}
//	
//	public void testPOW_17461() throws Exception
//	{
//		//NOTE: after this is run successfully, the record is no longer new to ES 
//		//since 200ESR correlaiton will be added. Need to find another record wo/ 200ESR Correlation
//		
//		Person incoming = new Person();
//		VOAApplication app = createDefaultVOAApplicationAndPerson("1005123867", new Date(53,6,15), "NATHAN", "EUGENE", "DOUGLAS", "M", "796121912", incoming );
////		this.getVoaApplicationService().save(app);
////		this.setComplete();
////		
//		this.attachPOW(incoming);
////		BigDecimal appId = (BigDecimal) app.getEntityKey().getKeyValue();
//		BigDecimal appId = new BigDecimal("375345548");
////		this.getVoaApplicationService().forwardVOAApplication(appId, incoming);
//		this.getVoaApplicationService().processVoaApplication(appId, incoming);
//
//	}
//	public void testPH_17386() throws Exception
//	{
//		Person incoming = new Person();
//		VOAApplication app = createDefaultVOAApplicationAndPerson("1005123867", new Date(53,6,15), "NATHAN", "EUGENE", "DOUGLAS", "M", "796121912", incoming );
////		this.getVoaApplicationService().save(app);
////		this.setComplete();
////		
//		this.attachPurpleHeartWithPHStatusPending(incoming);
//		this.setPurpleHeartToNo(incoming);
//		
////		BigDecimal appId = (BigDecimal) app.getEntityKey().getKeyValue();
//		BigDecimal appId = new BigDecimal("375345548");
////		this.getVoaApplicationService().forwardVOAApplication(appId, incoming);
//		this.getVoaApplicationService().processVoaApplication(appId, incoming);
//
//	}
//	
//	public void testPH_17387() throws Exception
//	{
//		Person incoming = new Person();
//		VOAApplication app = createDefaultVOAApplicationAndPerson("1005123867", new Date(53,6,15), "NATHAN", "EUGENE", "DOUGLAS", "M", "796121912", incoming );
////		this.getVoaApplicationService().save(app);
////		this.setComplete();
////		
//		this.attachPurpleHeartWithPHStatusPending(incoming);
////		BigDecimal appId = (BigDecimal) app.getEntityKey().getKeyValue();
//		BigDecimal appId = new BigDecimal("375345548");
////		this.getVoaApplicationService().forwardVOAApplication(appId, incoming);
//		this.getVoaApplicationService().processVoaApplication(appId, incoming);
//
//	}
//	
//	protected VOAApplication createDefaultVOAApplicationAndPerson(String edipi, Date birthDate, String firstName, String middleName, String lastName, String genderCd, String ssnTxt, Person person) throws Exception 
//	{
//		VOAApplication app = new VOAApplication();
//		app.setApplicationStatus((VOAApplicationStatus) this
//				.getLookupService().getByCode(VOAApplicationStatus.class,
//						VOAApplicationStatus.FORM_SUBMITTED));
//		
//		app.setAuthenticationLevel((AuthenticationLevel) this
//				.getLookupService().getByCode(AuthenticationLevel.class,
//						AuthenticationLevel.DS_LOGON_LEVEL_2));
//		app.setFullQualifiedId(edipi + "^NI^200DOD^USDOD");
//		app.setIdentityType((VeteranIdentifierType) this
//				.getLookupService().getByCode(VeteranIdentifierType.class,
//						VeteranIdentifierType.CODE_EDIPI));
//		app.setFormType((VOAFormType) this
//				.getLookupService().getByCode(VOAFormType.class,
//						VOAFormType.VOA_FORM_1010EZ));
//		app.setFirstName(firstName);
//		app.setLastName(lastName);
//		app.setSsn(ssnTxt);
//		app.setDateOfBirth(birthDate);
//		app.setGender(this.getLookupService().getGenderByCode(genderCd));
//		
//		
//		//building new person
//		person.addName(createName(lastName, firstName,
//				NameType.LEGAL_NAME.getName()));
//		person.getLegalName().setMiddleName(middleName);
//		person.setBirthRecord(this.createBirthRecord(new ImpreciseDate(birthDate)));
//		person.setGender(this.getLookupService().getGenderByCode(genderCd));
//		SSN ssn = new SSN();
//		ssn.setSsnText(ssnTxt);
//		ssn.setType((SSNType)getLookupService().getByCode(SSNType.class, SSNType.CODE_ACTIVE.getName()));
//		person.addSsn(ssn);
//		
//		//add simple  Perm address "Clairmont Dr, Atlanta,GA 30305"
//		//with now as updatedDate and null endDate */
//		this.addPermanentAddress(person, Calendar.getInstance().getTime(),null);
//		
//		return app;
//		
//	}
//	
//	public void testInsertPsPersonVpid() throws Exception
//	{
//		
//		SSN ssn = new SSN();
//		String ssnTxt = (ssn == null || ssn.getSsnText() ==null) ? null : ssn.getSsnText().toUpperCase();
//		ssn.setSsnText("123456789");
//		ssnTxt = (ssn == null || ssn.getSsnText() ==null) ? null : ssn.getSsnText().toUpperCase();
//		
//		String vpid = "0000001008589237V448346000000";
////		getPersonService().addPersonStub(new VPIDEntityKeyImpl(vpid));
//		
//		PersonVPID pv = new PersonVPID(vpid);
//		
//		this.getDAO().insertObject(pv);
//		
//		this.setComplete();
//		
//
//	}
}