package com.agilex.healthcare.schedulingmanager.datalayer;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.Date;

import javax.annotation.Resource;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.agilex.healthcare.schedulingmanager.datalayer.vista.util.AuthenticationUtil;
import com.agilex.healthcare.schedulingmanager.domain.AppointmentSlotFilter;
import com.agilex.healthcare.schedulingmanager.domain.AppointmentTimeSlot;
import com.agilex.healthcare.schedulingmanager.domain.AppointmentTimeSlots;
import com.agilex.healthcare.schedulingmanager.domain.AppointmentTypes;
import com.agilex.healthcare.schedulingmanager.mdws.connection.MdwsConfiguration;
import com.agilex.healthcare.utility.DateHelper;

@ContextConfiguration(locations = {"classpath:integrationApplicationContext.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class SchedulingDataLayerMdwsAppointmentVistaTest {
	
	@Resource
	MdwsConfiguration mdwsSchedulingConfiguration;

	@BeforeClass
	public static void login() {
		AuthenticationUtil.loginUser("777", "clerk3434", "clerk4343$", "1");
	}
	@AfterClass
	public static void logoff() {
		AuthenticationUtil.logoffUser();
	}

	@Test
	public void getAppointmentTypes() {
		SchedulingDataLayerMdws dl = new SchedulingDataLayerMdws(mdwsSchedulingConfiguration);
		AppointmentTypes types = dl.getAppointmentTypes("777");
		assertNotNull(types);
		assertEquals(11, types.getSize());
		assertNotNull(types.get(0));
		assertEquals("2", types.get(0).getId());
		assertEquals("CLASS II DENTAL", types.get(0).getName());
	}

	@Test
	public void getClinicSchedulingDetail() {
		SchedulingDataLayerMdws dl = new SchedulingDataLayerMdws(mdwsSchedulingConfiguration);
		Date startDate = DateHelper.parseVistaDefaultDateTIme("19900101.0000");
		Date endDate = DateHelper.parseVistaDefaultDateTIme("20131230.5959");
		AppointmentSlotFilter filter = new AppointmentSlotFilter();
		filter.setClinicId("23");
        filter.setSiteCode("777");
        filter.setStartDate(startDate);
        filter.setEndDate(endDate);
        AppointmentTimeSlots slots = dl.getClinicSchedulingDetail(filter);
		assertNotNull(slots);
		assertEquals(34129, slots.getSize());
		assertEquals("15", slots.getAppointmentLength());
		assertFalse(slots.isAskForCheckIn());
		assertEquals("8", slots.getClinicDisplayStartTime());
		assertEquals("23", slots.getClinicId());
		assertEquals("GENERAL MEDICINE", slots.getClinicName());
		assertEquals("532", slots.getCreditCode());
		assertEquals("4", slots.getDisplayIncrements());
		assertTrue(slots.isHasUserAccessToClinic());
		assertEquals("250", slots.getMaxOverbooksPerDay());
		assertEquals("9", slots.getSpecialty());
		assertEquals("141", slots.getStopCode());
		
		Date slotStartDate = DateHelper.parseVistaDefaultDateTIme("19931001.080000");
		Date slotEndDate = DateHelper.parseVistaDefaultDateTIme("19931001.081500");
		AppointmentTimeSlot slot = slots.get(0);
		assertTrue(slot.isAvailability());
		assertEquals("1", slot.getBookingStatus());
		assertEquals(slotEndDate, slot.getEndDateTime());
		assertEquals("250", slot.getRemainingAllowedOverBookings());
		assertEquals(slotStartDate, slot.getStartDateTime());
	}
}