package city.restaurant.omar;

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

import agent.Role;
import city.PersonAgent;
import city.interfaces.PlaceWithAnimation;
import city.restaurant.Restaurant;
import city.restaurant.RestaurantCustomerRole;
import city.restaurant.omar.gui.OmarRestaurantAnimationPanel;

public class OmarRestaurant extends Restaurant implements PlaceWithAnimation {

	public RevolvingStand revolving_stand = new RevolvingStand();
	//count stands for the number of waiting list
	int count = -1;
	int waiter_count = -1;
	boolean open;
	public OmarHostRole host;
	private List<Table> tables;
	public OmarCookRole cook;
	private int businessAccountNumber = -1;
	public List<OmarWaiterRole> Waiters = new ArrayList<OmarWaiterRole>();
	private OmarRestaurantAnimationPanel _animationPanel;
	
	// ------------- CONSTRUCTOR & PROPERTIES
	
	public OmarRestaurant(String name, gui.WorldViewBuilding worldViewBuilding, gui.BuildingInteriorAnimationPanel animationPanel){
		super(name, worldViewBuilding);

		this._animationPanel = (OmarRestaurantAnimationPanel)animationPanel.getBuildingAnimation();

		// The animation object for these will be instantiated when a person enters the building and takes the role.
		cashier = new OmarCashierRole(null,this);
		host = new OmarHostRole(null,this,"Host");
		_animationPanel.setHost(host);
		tables = host.getTableList();
		cook = new OmarCookRole(null,null, this);
		((OmarCookRole)cook).cashier = (OmarCashierRole)cashier;
	}

	//default constructor for unit testing DO NOT DELETE
	public OmarRestaurant(){
		super("Omar's Restaurant");    
		cashier = new OmarCashierRole(null,this);
		host = new OmarHostRole(null,this,"Host");
		cook = new OmarCookRole(null,null, this);
		((OmarCookRole)cook).cashier = (OmarCashierRole)cashier;
	}

	public boolean isOpen(){
		if (cashier.active && host.active && cook.active && Waiters.size()!=0)
			return true;
		else
			return false;
	}

	@Override
	public RestaurantCustomerRole generateCustomerRole(PersonAgent person) {
		return (new OmarCustomerRole(person, this, person.getName()));
	}

	@Override
	public Role generateWaiterRole(PersonAgent person) {
		int i = (new Random()).nextInt(2);
		OmarWaiterRole newWaiter;
		if (i == 0)
			newWaiter = new OmarWaiterRole(person, this,cook, host, null);
		else
			newWaiter = new OmarWaiterRole(person, this, cook, host, null);
		newWaiter.setCashier((OmarCashierRole)cashier);
		waiter_count++;
		return newWaiter;
	}

	public void updateAccountNumber(int newAccountNumber){
		this.businessAccountNumber = newAccountNumber;
	}

	public int getAccountNumber(){
		return this.businessAccountNumber;
	}

	@Override
	public Role getHostRole() {
		return host;
	}

	public int waiterCount(){
		return waiter_count;
	}
	
	public OmarRestaurantAnimationPanel getAnimationPanel() {
		return this._animationPanel;
	}
}

@@ -331,16 +331,112 @@
 onPanel;
+%0Aimport city.restaurant.omar.gui.OmarWaiterGui;%0Aimport city.restaurant.yixin.gui.YixinWaiterGui;
 %0A%0Apublic
@@ -640,32 +640,8 @@
 -1;%0A
-%09int waiter_count = -1;%0A
 %09boo
@@ -2419,32 +2419,42 @@
 aiter = new Omar
+SharedData
 WaiterRole(perso
@@ -2537,22 +2537,151 @@
 ;%0A%09%09
-waiter_count++
+OmarWaiterGui waiterGui = new OmarWaiterGui(newWaiter, _animationPanel);%0A%09%09newWaiter.setGui(waiterGui);%0A%09%09getAnimationPanel().addGui(waiterGui)
 ;%0A%09%09
@@ -2945,62 +2945,8 @@
 ;%0A%09%7D
-%0A%0A%09public int waiterCount()%7B%0A%09%09return waiter_count;%0A%09%7D
 %0A%09%0A%09

add gui creation in Omar Restaurant