package managedbean.visit;

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

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;

import TO.VisitTO;
import managedbean.common.ManagedBeanBase;
import managedbean.common.SessionUtils;

@Named("VisitList")
@RequestScoped
public class VisitListMBean extends ManagedBeanBase implements Serializable {

	private static final long serialVersionUID = 1L;

	private int familyDoctorId;
	private LazyDataModel<VisitTO> lazyDataModelVisitList;
	private Date selectedDate;

	public VisitListMBean() {
	}

	@PostConstruct
	public void init() {
		// El usuario actual es un medico de familia, recuperamos su Id de la sessión actual
		this.familyDoctorId = Integer.valueOf(SessionUtils.getUserId());
		this.selectedDate = new Date();

		this.lazyDataModelVisitList = new LazyDataModel<VisitTO>() {
			private static final long serialVersionUID = 1L;

			@Override
			public List<VisitTO> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
				Long totalRowCount = getRemoteManagerMedicalTest().getPendingQuestionsCount(familyDoctorId);
				this.setRowCount(totalRowCount.intValue());

				return getRemoteManagerVisit().listAllScheduledVisitsPaged(familyDoctorId, selectedDate, (first / pageSize), pageSize);
			}
		};
	}

	public LazyDataModel<VisitTO> getLazyDataModelVisitList() {
		return lazyDataModelVisitList;
	}

	public void saveData() {

	}
	
	public void showData() {

	}

	public Date getSelectedDate() {
		return selectedDate;
	}

	public void setSelectedDate(Date selectedDate) {
		this.selectedDate = selectedDate;
	}
}
