/*
 * generated by Xtext 2.25.0
 */
package org.etsi.mts.tdl.ui.contentassist;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.Assignment;
import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext;
import org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor;
import org.etsi.mts.tdl.Connection;
import org.etsi.mts.tdl.Member;
import org.etsi.mts.tdl.Message;
import org.etsi.mts.tdl.Target;
import org.etsi.mts.tdl.StructuredDataInstance;
import org.etsi.mts.tdl.StructuredDataType;

/**
 * See https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#content-assist
 * on how to customize the content assistant.
 */
public class TDLtxProposalProvider extends AbstractTDLtxProposalProvider {
	@Override
	public void completeMemberAssignment_Member(EObject model, Assignment assignment, ContentAssistContext context,
			ICompletionProposalAcceptor acceptor) {
		// TODO Auto-generated method stub
		//super.completeMemberAssignment_Member(model, assignment, context, acceptor);
		
		// compute the plain proposal
		for (Member m : ((StructuredDataType)
				((StructuredDataInstance)model).getDataType()).allMembers()) {
			acceptor.accept(createCompletionProposal(m.getName(), context));
		}
	    // Create and register the completion proposal:
	    // The proposal may be null as the createCompletionProposal(..) 
	    // methods check for valid prefixes and terminal token conflicts.
	    // The acceptor handles null-values gracefully.
	}
	@Override
	public void complete_FunctionCall(EObject model, RuleCall ruleCall, ContentAssistContext context,
			ICompletionProposalAcceptor acceptor) {
		acceptor.accept(createCompletionProposal("instance returned from ",context));
		super.complete_FunctionCall(model, ruleCall, context, acceptor);
	}
	
	@Override
	public void completePredefinedFunctionCallBinary_Function(EObject model, Assignment assignment,
			ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		// TODO: handle here or in scope provider - exclude incorrect proposals 
		super.completePredefinedFunctionCallBinary_Function(model, assignment, context, acceptor);
	}

	@Override
	public void completePredefinedFunctionCallBinary_ActualParameters(EObject model, Assignment assignment,
			ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		// TODO: refine?
		super.completePredefinedFunctionCallBinary_ActualParameters(model, assignment, context, acceptor);
	}
	
	@Override
	public void complete_PredefinedFunctionCallBinary(EObject model, RuleCall ruleCall, ContentAssistContext context,
			ICompletionProposalAcceptor acceptor) {
		// TODO: refine?
		super.complete_PredefinedFunctionCallBinary(model, ruleCall, context, acceptor);
	}
	
	@Override
	public void complete_TargetMessage(EObject model, RuleCall ruleCall, ContentAssistContext context,
			ICompletionProposalAcceptor acceptor) {
		super.complete_TargetMessage(model, ruleCall, context, acceptor);
	}
	
	@Override
	public void completeMessage_Target(EObject model, Assignment assignment, ContentAssistContext context,
			ICompletionProposalAcceptor acceptor) {
		super.completeMessage_Target(model, assignment, context, acceptor);
	}
	
	@Override
	public void completeTargetMessage_TargetGate(EObject model, Assignment assignment, ContentAssistContext context,
			ICompletionProposalAcceptor acceptor) {
		super.completeTargetMessage_TargetGate(model, assignment, context, acceptor);
		EList<Connection> connection = ((Message) model).getParentTestDescription().getTestConfiguration().getConnection();
		for (Connection c : connection) {
			//TODO: simplify, filter? move upstream?, also for procedure target?
			acceptor.accept(createCompletionProposal(c.getEndPoint().get(0).getComponent().getName()+"::"+c.getEndPoint().get(0).getGate().getName(), context));
			acceptor.accept(createCompletionProposal(c.getEndPoint().get(1).getComponent().getName()+"::"+c.getEndPoint().get(1).getGate().getName(), context));
		}
	}
	
	@Override
	public void complete_TimeConstraintFragment(EObject model, RuleCall ruleCall, ContentAssistContext context,
			ICompletionProposalAcceptor acceptor) {
		acceptor.accept(createCompletionProposal("{  }",context));
		super.complete_TimeConstraintFragment(model, ruleCall, context, acceptor);
	}
	
}
