package core.entities.menus;

import java.util.ArrayList;
import java.util.List;

import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageChannel;

public class Menu {
	
	private List<MenuItem> menuItemList = new ArrayList<MenuItem>();
	private MessageChannel channel;
	private Message statusMessage = null;
	
	
	public Menu(MessageChannel c){
		this.channel = c;
	}
	
	public MenuItem getMenuItem(String id){
		for(MenuItem m : menuItemList){
			if (m.getId().equals(id)){
				return m;
			}
		}
		return null;
	}
	
	public MenuItem getMenuItemByText(String text){
		for(MenuItem m : menuItemList){
			if (m.getText().equals(text)){
				return m;
			}
		}
		return null;
	}
	
	public void createMenuItem(String text, String[] buttons){
		menuItemList.add(new MenuItem(channel, text, buttons));
	}
	
	public void createMenuItem(String text, String button){
		menuItemList.add(new MenuItem(channel, text, button));
	}
	
	public void createStatusMessage(String text){
		statusMessage = channel.sendMessage(text).complete();
	}
	
	public void editStatusMessage(String text){
		statusMessage.editMessage(text).complete();
	}
	
	public MessageChannel getChannel(){
		return channel;
	}
	
	public void deleteMenuItems(){
		menuItemList.forEach((mi) -> mi.remove());
		menuItemList.clear();
	}
	
	public void deleteMenuItem(MenuItem mi){
		mi.remove();
		menuItemList.remove(mi);
	}
	
	public void deleteStatusMessage(){
		if(statusMessage != null){
			statusMessage.delete().complete();
		}
	}
}

@@ -340,61 +340,296 @@
 l;%0A%09
-%0A%09%0A%09public Menu(MessageChannel c)%7B%0A%09%09this.channel = c
+private MenuStatus menuStatus = null;%0A%09%0A%09public enum MenuStatus%7B%0A%09%09INITIALIZING,%0A%09%09COMPLETE,%0A%09%09ABORTED;%0A%09%7D%0A%09%0A%09public Menu(MessageChannel c)%7B%0A%09%09this.channel = c;%0A%09%09this.menuStatus = MenuStatus.INITIALIZING;%0A%09%7D%0A%09%0A%09public void changeMenuStatus(MenuStatus newStatus)%7B%0A%09%09menuStatus = newStatus
 ;%0A%09%7D
@@ -771,32 +771,116 @@
 turn null;%0A%09%7D%0A%09%0A
+%09public MenuItem getMenuItem(Integer index)%7B%0A%09%09return menuItemList.get(index);%0A%09%7D%0A%09%0A
 %09public MenuItem
@@ -1079,24 +1079,65 @@
 %5D buttons)%7B%0A
+%09%09if(menuStatus != MenuStatus.ABORTED)%7B%0A%09
 %09%09menuItemLi
@@ -1178,24 +1178,28 @@
  buttons));%0A
+%09%09%7D%0A
 %09%7D%0A%09%0A%09public
@@ -1248,16 +1248,57 @@
 utton)%7B%0A
+%09%09if(menuStatus != MenuStatus.ABORTED)%7B%0A%09
 %09%09menuIt
@@ -1346,16 +1346,20 @@
 tton));%0A
+%09%09%7D%0A
 %09%7D%0A%09%0A%09pu
@@ -1394,32 +1394,73 @@
 e(String text)%7B%0A
+%09%09if(menuStatus != MenuStatus.ABORTED)%7B%0A%09
 %09%09statusMessage 
@@ -1491,32 +1491,36 @@
 xt).complete();%0A
+%09%09%7D%0A
 %09%7D%0A%09%0A%09public voi
@@ -1553,16 +1553,57 @@
  text)%7B%0A
+%09%09if(menuStatus != MenuStatus.ABORTED)%7B%0A%09
 %09%09status
@@ -1636,24 +1636,28 @@
 complete();%0A
+%09%09%7D%0A
 %09%7D%0A%09%0A%09public

Add MenuStatus enum and do not allow menuitem modifications if the menu has aborted