package controller.commande;

import org.sig.fw.db.corrida.model.Commande_Content;
import org.sig.fw.db.corrida.model.Commande_Reference;

import controller.history.Application_Controller;
import view.commande.Add_Commande_Content_View;

public class Add_Commande_Content_Controller 
{
	private Application_Controller ctrl_application;
	private Add_Commande_Controller ctrl_add_commande;
	private Add_Commande_Content_View vw_commande_content;
	
	private Commande_Content mdl_commande_content;
	
	private Commande_Reference_Controller ctrl_commande_reference;
	
	private boolean readOnly = false;
	
	public Add_Commande_Content_Controller(Application_Controller ctrl_application, Add_Commande_Controller ctrl_add_commande, Commande_Content mdl_commande_content)
	{
		super();
		this.ctrl_add_commande = ctrl_add_commande;
		if(mdl_commande_content == null)
			this.mdl_commande_content = new Commande_Content(-1);
		else
			this.mdl_commande_content = mdl_commande_content;
		this.vw_commande_content = new Add_Commande_Content_View(this);
		this.ctrl_commande_reference = new Commande_Reference_Controller();
		this.ctrl_application = ctrl_application;
	}
	
	public void setReadOnly(boolean readOnly)
	{
		vw_commande_content.setReadOnly(readOnly);
		this.readOnly = true;
	}
	
	public boolean getReadOnly()
	{
		return this.readOnly;
	}
	
	public Add_Commande_Content_View getView()
	{
		return this.vw_commande_content;
	}
	
	public Commande_Content getModel()
	{
		return this.mdl_commande_content;
	}
	
	public Application_Controller getApplicationController()
	{
		return this.ctrl_application;
	}
	
	public void addLine(int type)
	{
		ctrl_add_commande.addLine(this.mdl_commande_content.getIndex()+type);
		setIsSave(false);
	}
	
	public void moveLine(int type)
	{
		ctrl_add_commande.moveLine(this.mdl_commande_content.getIndex(), type);
		setIsSave(false);
	}
	
	public void removeLine()
	{
		ctrl_add_commande.removeLine(this.mdl_commande_content.getIndex());
		setIsSave(false);
	}
	
	public void updateTotal()
	{
		ctrl_add_commande.updateTotal();
	}
	
	public void setAmountHt(double amount_ht)
	{
		this.mdl_commande_content.setAmountHt(amount_ht);
		this.vw_commande_content.setAmountHt(amount_ht);
	}
	
	public void setIsSave(boolean isSave)
	{
		ctrl_add_commande.setSave(isSave);
	}

	public Commande_Reference openCommandeReferenceView() 
	{
		return ctrl_commande_reference.show();
	}
	
	public void updateCommandeReference()
	{
		ctrl_commande_reference.updateModel();
	}
}
