package gov.va.med.esr.common.batchprocess;

import java.util.ArrayList;

import gov.va.med.esr.common.model.comms.CmsErrorFileEntry;
import gov.va.med.esr.common.model.comms.CmsMailedFileEntry;
import gov.va.med.esr.common.model.comms.CmsRejectFileEntry;
import gov.va.med.esr.common.model.comms.CmsReturnedByUSPSFileEntry;
import gov.va.med.esr.common.model.comms.CommsImportStatistics;
import gov.va.med.esr.common.persistent.comms.ImportFileDAO;
import gov.va.med.esr.common.util.RuleAbstractTestCase;

public class TestCmsImportProcess extends RuleAbstractTestCase {

	public TestCmsImportProcess() {
		// TODO Auto-generated constructor stub
	}

	public TestCmsImportProcess(String testName) {
		super(testName);

	}

	public void testCmsImportProcessStraight() {
		// login anonymous
		this.getLoginManager().loginAnonymous();

		try {
			CmsImportProcess proc = (CmsImportProcess) applicationContext
					.getBean("cmsImportProcess");
			CommsImportStatistics stats = proc.execute(null);
			System.out.println("stats="
					+ stats.getReturnedMailFileProcessedCount());
		} catch (Exception ex) {
			ex.printStackTrace();
		}

	}

	public void testImportDAO_reads() throws Exception {
		ImportFileDAO dao = (ImportFileDAO) applicationContext
				.getBean("importFileDAO");
		CommsImportStatistics stats = new CommsImportStatistics();

		CmsMailedFileEntry mailed = null;
		CmsRejectFileEntry reject = null;
		CmsErrorFileEntry error = null;
		CmsReturnedByUSPSFileEntry usps = null;

		ArrayList list = dao.readCmsMailedFile(stats);
		if (list != null) {
			mailed = (CmsMailedFileEntry) list.get(0);
			if (mailed != null)
				System.out.println(mailed);
			System.out.println("entry=" + mailed + "\n" + mailed.getBarCode()
					+ "\n" + mailed.getCommunicationId() + "\n"
					+ mailed.getFormNumber());
		}

		list = dao.readCmsErrorFile(stats);
		if (list != null) {
			error = (CmsErrorFileEntry) list.get(0);
			if (error != null)
				System.out.println("error=" + error + "\n" + error.getBarCode()
						+ "\n" + error.getCommunicationId() + "\n"
						+ error.getFormNumber() + "\n" + error.getErrorCode());
		}

		list = dao.readCmsRejectFile(stats);
		if (list != null) {
			reject = (CmsRejectFileEntry) list.get(0);
			if (reject != null)
				System.out.println("reject=" + reject + "\n"
						+ reject.getBarCode() + "\n"
						+ reject.getCommunicationId() + "\n"
						+ reject.getFormNumber() + "\n"
						+ reject.getCode1Reject());
		}

		list = dao.readCmsReturnedMailFile(stats);
		if (list != null) {
			usps = (CmsReturnedByUSPSFileEntry) list.get(0);
			if (usps != null)
				System.out.println("returned=" + usps + "\n"
						+ usps.getBarCode() + "\n" + usps.getCommunicationId()
						+ "\n" + usps.getFormNumber() + "\n");
		}
	}
}
