package info.bukova.isspst.ui.reporting;

import info.bukova.isspst.reporting.Report;
import info.bukova.isspst.reporting.ReportDefinition;
import info.bukova.isspst.reporting.ReportType;
import info.bukova.isspst.sort.ReflectionTools;
import info.bukova.isspst.ui.DocumentViewModel;
import info.bukova.isspst.ui.ListChecks;
import info.bukova.isspst.ui.LocaleConverter;

import java.util.List;

import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.select.annotation.WireVariable;

public class ColSelectVM extends DocumentViewModel
{
	@WireVariable
	private ReportDefinition reportDefinition;
	private LocaleConverter locConverter;
	
	@Init(superclass = true)
	public void init() {
		locConverter = new LocaleConverter();
	}
	
	public ListChecks<String> getColumns() {
		Report selected = reportDefinition.getReport();
		List<Object> data = reportDefinition.getDataSet();
		
		if (selected == null || selected.getType() != ReportType.DYNAMIC) {
			return null;
		}
		if (data == null || data.size() == 0) {
			return null;
		}
		
		List<String> properties = ReflectionTools.getEntityFields(data.get(0));
		ListChecks<String> columns = new ListChecks<String>(reportDefinition.getFieldsToPrint(), properties);
		
		return columns;
	}

	public LocaleConverter getLocConverter() {
		return locConverter;
	}

	public ReportDefinition getReportDefinition() {
		return reportDefinition;
	}

}
