package com.jasamedika.medifirst2000.asynctask;

import java.util.Calendar;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import com.jasamedika.medifirst2000.asynctask.timer.LogbookVerificationTimer;
import com.jasamedika.medifirst2000.controller.base.LocaleController;
import com.jasamedika.medifirst2000.service.LogbookKinerjaService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.LogbookKinerjaVO;

@Component
public class AutoLogbookVerification extends LocaleController<LogbookKinerjaVO> {
	private final static Logger LOGGER = LoggerFactory.getLogger(AutoLogbookVerification.class);

	@Autowired
	private LogbookKinerjaService logbookKinerjaService;

	public AutoLogbookVerification() {
//		int day = 5;
//		int hour = 0;
//		int minute = 00;
//		LogbookVerificationTimer.schedule(new Runnable() {
//			@Override
//			public void run() {
//				try {
//					LOGGER.info("Task Logbook Verification : Running Task Logbook Verification");
//					autoLogbookVerification();
//				} catch (Exception ex) {
//					LOGGER.error("Task Logbook Verification : Task Logbook Verification " + ex.getMessage());
//				} finally {
//					LOGGER.info("Task Logbook Verification : Finishing Task Logbook Verification");
//				}
//			}
//		}, day, hour, minute);
	}

//	@Async
	public void autoLogbookVerification() {
		try {
			if (CommonUtil.isNotNullOrEmpty(logbookKinerjaService)) {
				LOGGER.info("Task Logbook Verification : Running Automatic Logbook Verification");

				Calendar cal = Calendar.getInstance();
				cal.add(Calendar.MONTH, -1);
				logbookKinerjaService.autoVerifLogbookJamKerjaDokter(cal.getTime());
			} else {
				LOGGER.warn("Task Logbook Verification : Undefined service");
			}
		} catch (Exception ex) {
			LOGGER.error("Task Logbook Verification : Automatic Logbook Verification " + ex.getMessage());
		} finally {
			LOGGER.info("Task Logbook Verification : Finishing Automatic Logbook Verification");
		}
	}

}