package com.jasamedika.medifirst2000.asynctask;

import java.text.SimpleDateFormat;
import java.util.Date;

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.TargetLayananTimer;
import com.jasamedika.medifirst2000.controller.base.LocaleController;
import com.jasamedika.medifirst2000.service.IkiDanRemunerasiService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.TargetLayananVO;

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

	@Autowired
	private IkiDanRemunerasiService remunerasiService;

	/**
	 * Disabled following update business rules
	 * @since 2022/08/28
	 */
	public TargetLayananGenerating() {
//		int day = 4;
//		int hour = 0;
//		int minute = 00;
//		TargetLayananTimer.schedule(new Runnable() {
//			@Override
//			public void run() {
//				try {
//					LOGGER.info("Task Target Layanan : Running Task Target Layanan");
//					genTargetLayanan();
//				} catch (Exception ex) {
//					LOGGER.error("Task Target Layanan : Task Target Layanan " + ex.getMessage());
//				} finally {
//					LOGGER.info("Task Target Layanan : Finishing Task Target Layanan");
//				}
//			}
//		}, day, hour, minute);
	}

//	@Async
	public void genTargetLayanan() {
		// Jam Kerja
		try {
			if (CommonUtil.isNotNullOrEmpty(remunerasiService)) {
				LOGGER.info("Task Target Layanan Jam Kerja : Running Generate Target Layanan Jam Kerja");
				remunerasiService
						.autoSaveTargetCapaianLayananJamKerja(new SimpleDateFormat("yyyy-MM").format(new Date()));
			} else {
				LOGGER.warn("Task Target Layanan Jam Kerja : Undefined service");
			}
		} catch (Exception ex) {
			LOGGER.error("Task Target Layanan Jam Kerja : Generate Target Layanan Jam Kerja : " + ex.getMessage());
			ex.printStackTrace();
		} finally {
			LOGGER.info("Task Target Layanan Jam Kerja : Finishing Generate Target Layanan Jam Kerja");
		}

		// Luar Jam Kerja
		try {
			if (CommonUtil.isNotNullOrEmpty(remunerasiService)) {
				LOGGER.info("Task Target Layanan Luar Jam Kerja : Running Generate Target Layanan Luar Jam Kerja");
				remunerasiService
						.autoSaveTargetCapaianLayananLuarJamKerja(new SimpleDateFormat("yyyy-MM").format(new Date()));
			} else {
				LOGGER.warn("Task Target Layanan Luar Jam Kerja : Undefined service");
			}
		} catch (Exception ex) {
			LOGGER.error(
					"Task Target Layanan Luar Jam Kerja : Generate Target Layanan Luar Jam Kerja : " + ex.getMessage());
			ex.printStackTrace();
		} finally {
			LOGGER.info("Task Target Layanan Luar Jam Kerja : Finishing Generate Target Layanan Luar Jam Kerja");
		}
	}

}