package com.sh.djpk.econsole.ui.controller.monitoring;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sh.djpk.econsole.ui.controller.HeaderTemplate;
import com.sh.djpk.share.model.RestResponse.HttpMethod;
import com.sh.djpk.share.util.ClientsUtil;

@ManagedBean
@SessionScoped
public class NasionalMonitoring implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Map<String,Object> dummyLoad = new HashMap<>();
	public static final Logger LOGGER = LoggerFactory.getLogger(NasionalMonitoring.class);
	
	List<Map<String, Object>> listMonitor;

	private int tahun;
	
	@PostConstruct
    public void init() {
		listMonitor = ClientsUtil.callWsListResponse(
				"/monitoring/nasional", dummyLoad, HttpMethod.POST,
				"tahun=" + getSessionTahunAnggaran());
	}
	
	public int getSessionTahunAnggaran() {
		HttpServletRequest request = (HttpServletRequest) FacesContext
				.getCurrentInstance().getExternalContext().getRequest();
		HttpSession session = request.getSession(true);
		HeaderTemplate hdrT = (HeaderTemplate) session
				.getAttribute("headerTemplate");
		int i = hdrT.getTahunAnggaran();
		return i;
	}

	public List<Map<String, Object>> getListMonitor() {
		return listMonitor;
	}

	public void setListMonitor(List<Map<String, Object>> listMonitor) {
		this.listMonitor = listMonitor;
	}

	public int getTahun() {
		return getSessionTahunAnggaran();
	}

	public void setTahun(int tahun) {
		this.tahun = tahun;
	}
}
