package org.ellectra.gui.managebeans;

import java.util.Date;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import javax.faces.validator.ValidatorException;

/**
 * 
 * Class to hold the information of ANNEX B: Information about Lots 
 *
 */
public class AnnexB {

	private Double a149;
	private String a150;
	private String a151;
	private String a156;
	private String a172;
	private String a157_160;
	private String a158_159Disabled;
	private String a161_162_163Disabled;
	private Double a158;
	private String a159;	//currency
	private Double a161;
	private Double a162;
	private String a163;	//currency
	private Double a168;
	private String a165_a167_a169;
	private Double a166;
	private String a166Disabled;
	private String a168Disabled;
	private String a170_171Disabled;
	
	private Date a164;
	private Date a170;
	private Date a171;
	
	//TODO: CPV as obligatory field
	
	public void eventSelectCostB(ValueChangeEvent vce) {
		a157_160 = (String) vce.getNewValue();
		if (a157_160.equals("Option1")) {
			setA158_159Disabled("false");
			setA161_162_163Disabled("true");
		}
		else { 
			setA158_159Disabled("true");
			setA161_162_163Disabled("false");
		}
	}
	
	public void eventSelectDurationB(ValueChangeEvent vce) {
		a165_a167_a169 = (String) vce.getNewValue();
		if (a165_a167_a169.equals("Duration in months"))
			setA166Disabled("false");
		else if (a165_a167_a169.equals("Duration in days"))
			setA168Disabled("false");
		else if (a165_a167_a169.equals("OR Scheduled date"))
			setA170_171Disabled("false");
	}
	
	public void validateA162 (FacesContext context, UIComponent toValidate, Object value) throws ValidatorException {
		Double a162 = (Double)value;
		if (getA161() > a162) {
			FacesMessage message = new FacesMessage("The number entered is less than or equal to " + getA161());
			context.addMessage("pinForm", message);
			throw new ValidatorException(message);
		}
	}
	public void eventA170(ValueChangeEvent vce) {
		a170 = (Date) vce.getNewValue();
	}
	public void eventA171(ValueChangeEvent vce) {
		a171 = (Date) vce.getNewValue();
	}
	
	public void validateA171 (FacesContext context, UIComponent toValidate, Object value) throws ValidatorException {
		Date a171 = (Date)value;
		Date a170 = getA170();
		if (a171.before(a170) || a171.equals(a170)) {
			FacesMessage message = new FacesMessage("Date in 'completion of works' must be after date 'start of works'");
			context.addMessage("pinForm", message);
			throw new ValidatorException(message);
		}
	}
	
	public void eventA161(ValueChangeEvent vce) {
		a161 = (Double) vce.getNewValue();
	}
	
	public void eventA162(ValueChangeEvent vce) {
		a162 = (Double) vce.getNewValue();
	}
	
	public Double getA149() {
		return a149;
	}

	public void setA149(Double a149) {
		this.a149 = a149;
	}

	public String getA150() {
		return a150;
	}

	public void setA150(String a150) {
		this.a150 = a150;
	}

	public String getA151() {
		return a151;
	}

	public void setA151(String a151) {
		this.a151 = a151;
	}

	public String getA156() {
		return a156;
	}

	public void setA156(String a156) {
		this.a156 = a156;
	}

	public String getA172() {
		return a172;
	}

	public void setA172(String a172) {
		this.a172 = a172;
	}

	public Date getA164() {
		return a164;
	}

	public void setA164(Date a164) {
		this.a164 = a164;
	}

	public Date getA170() {
		return a170;
	}

	public void setA170(Date a170) {
		this.a170 = a170;
	}

	public Date getA171() {
		return a171;
	}

	public void setA171(Date a171) {
		this.a171 = a171;
	}

	public String getA157_160() {
		return a157_160;
	}

	public void setA157_160(String a157_160) {
		this.a157_160 = a157_160;
	}

	public String getA158_159Disabled() {
		return a158_159Disabled;
	}

	public void setA158_159Disabled(String disabled) {
		a158_159Disabled = disabled;
	}

	public String getA161_162_163Disabled() {
		return a161_162_163Disabled;
	}

	public void setA161_162_163Disabled(String disabled) {
		a161_162_163Disabled = disabled;
	}

	public Double getA158() {
		return a158;
	}

	public void setA158(Double a158) {
		this.a158 = a158;
	}

	public String getA159() {
		return a159;
	}

	public void setA159(String a159) {
		this.a159 = a159;
	}

	public Double getA161() {
		return a161;
	}

	public void setA161(Double a161) {
		this.a161 = a161;
	}

	public Double getA162() {
		return a162;
	}

	public void setA162(Double a162) {
		this.a162 = a162;
	}

	public String getA163() {
		return a163;
	}

	public void setA163(String a163) {
		this.a163 = a163;
	}

	public Double getA166() {
		return a166;
	}

	public void setA166(Double a166) {
		this.a166 = a166;
	}

	public Double getA168() {
		return a168;
	}

	public void setA168(Double a168) {
		this.a168 = a168;
	}

	public String getA165_a167_a169() {
		return a165_a167_a169;
	}

	public void setA165_a167_a169(String a165_a167_a169) {
		this.a165_a167_a169 = a165_a167_a169;
	}

	public String getA166Disabled() {
		return a166Disabled;
	}

	public void setA166Disabled(String disabled) {
		a166Disabled = disabled;
	}

	public String getA168Disabled() {
		return a168Disabled;
	}

	public void setA168Disabled(String disabled) {
		a168Disabled = disabled;
	}

	public String getA170_171Disabled() {
		return a170_171Disabled;
	}

	public void setA170_171Disabled(String disabled) {
		a170_171Disabled = disabled;
	}


}
