
package AOMCase;

import com.metamaxim.modelscope.callbacks.*;

public class AcceptRequest extends Event {

  public void handleEvent() {
	  //If this Resorce is still available and the Mission is not accomplished, assign to the Mission
	  if (this.getInstance("Assignment Request").getInstance("Internal Resource").getState("Internal Resource").equals("available")
	  		&&
	  	  this.getInstance("Assignment Request").getInstance("For Mission").getState("Internal Mission").equals("confirmed")) {
		  //Send the Accept Request to the model to change its state to accepted
		  this.submitToModel();
		  //Create and send an Assign Internal Resource event to the model to assign the Resource to the Mission
		  Event assign = this.createEvent("Assign Internal Resource");
		  assign.setInstance("Internal Resource", this.getInstance("Assignment Request").getInstance("Internal Resource"));
		  assign.setInstance("Mission", this.getInstance("Assignment Request").getInstance("For Mission"));
		  assign.submitToModel();
		  }
	  else {
	  //Otherwise cancel the event with a message
	      String missionName = this.getInstance("Assignment Request").getInstance("For Mission").getString("Internal Mission Name");
		  this.rollback("Resource assigned or Mission accomplished. " + missionName);
		  }
	  }

}


