package com.mx.dla.dda.reporte.oyp;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.Test;

import com.mx.dla.dda.common.test.BaseDaoTest;
import com.mx.dla.dda.reporte.oyp.daos.ReporteOveragesYPaymentsDAO;

public class ReporteOveragesYPaymentsTest extends BaseDaoTest {

	@Autowired
	private ReporteOveragesYPaymentsDAO reporteOveragesYPaymentsDAO;

	/*
	@Test(enabled = true)
	public void obtenerOveragesYPaymentsTest() throws IllegalArgumentException, IllegalAccessException {

		Long mesInicial = 6L;
		Long anioInicial = 2017L;
		Long mesFinal = 7L;
		Long anioFinal = 2017L;

		String fechaInicio = mesInicial + "/" + anioInicial;
		String fechaFin = mesFinal + "/" + anioFinal;
		String tipo_pago = null;//"Type 2";
		String sumatorias_mensuales = "";
		String meses_seleccionados = "";
		String meses_pivote = "";

		SimpleDateFormat formater = new SimpleDateFormat("MM/yyyy");

		Calendar beginCalendar = Calendar.getInstance();
		Calendar finishCalendar = Calendar.getInstance();

		try {
			beginCalendar.setTime(formater.parse(fechaInicio));
			finishCalendar.setTime(formater.parse(fechaFin));

			logger.info("{} {}", beginCalendar.getTime(), finishCalendar.getTime());
		}
		catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		Integer index = 1;
		while (beginCalendar.before(finishCalendar) || beginCalendar.equals(finishCalendar)) {
			// add one month to date per loop
			logger.info("{} {}", beginCalendar.get(Calendar.MONTH) + 1, beginCalendar.get(Calendar.YEAR));
			String month = StringUtils.leftPad(String.valueOf(beginCalendar.get(Calendar.MONTH) + 1), 2, "0");
			String year = String.valueOf(beginCalendar.get(Calendar.YEAR));

			sumatorias_mensuales = sumatorias_mensuales + "SUM(MES_" + index + ") as M" + index + ",";
			meses_seleccionados = meses_seleccionados + "NVL( MES_" + index + ", 0 ) as MES_" + index + ",";
			meses_pivote = meses_pivote + "'" + month + year + "' as MES_" + index + ",";

			beginCalendar.add(Calendar.MONTH, 1);
			index++;
		}

		logger.info("{}", sumatorias_mensuales.substring(0, sumatorias_mensuales.length() - 1));
		logger.info("{}", meses_seleccionados.substring(0, meses_seleccionados.length() - 1));
		logger.info("{}", meses_pivote.substring(0, meses_pivote.length() - 1));

		List<Map<String, String>> response = reporteOveragesYPaymentsDAO.obtenerOveragesYPayments(mesInicial, anioInicial, mesFinal, anioFinal, tipo_pago,
		        sumatorias_mensuales.substring(0, sumatorias_mensuales.length() - 1), meses_seleccionados.substring(0, meses_seleccionados.length() - 1),
		        meses_pivote.substring(0, meses_pivote.length() - 1));

		for (Map<String, String> item : response)
			for (Map.Entry<String, String> pair : item.entrySet())
				logger.info("{} : {}", pair.getKey(), pair.getValue());

		logger.info("{}", response);
	}*/

}
