package info.bukova.isspst.ui.limits;

import info.bukova.isspst.data.Limit;
import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.services.limits.LimitService;
import info.bukova.isspst.services.settings.SeasonService;
import info.bukova.isspst.services.workgroups.WorkgroupService;
import info.bukova.isspst.ui.FormViewModel;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.select.annotation.WireVariable;

import java.util.List;

public class LimitsForm extends FormViewModel<Limit> {

	List<Workgroup> workgroups;
	@WireVariable
	WorkgroupService workgroupService;
	@WireVariable
	LimitService limitService;
	@WireVariable
	SeasonService seasonService;

	@Init(superclass = true)
	public void init() {
		workgroups = workgroupService.getWorkgroups();
		if (getDataBean().getWorkgroup() == null) {
			List<Limit> limits = limitService.getForSeason(seasonService.getActive());

			for (Limit l : limits) {
				workgroups.remove(l.getWorkgroup());
			}
		}
	}

	public List<Workgroup> getWorkgroups() {
		return workgroups;
	}

	public boolean isNewRec() {
		return newRec;
	}
}
