<commit_before>package city.restaurant.yixin;

import java.util.*;

import utilities.EventLog;
import utilities.LoggedEvent;
import city.*;
import city.market.*;
import city.restaurant.RestaurantCashierRole;
import city.restaurant.yixin.gui.YixinCashierGui;

public class YixinCashierRole extends RestaurantCashierRole{// implements Cashier{
	public YixinRestaurant restaurant;
	public YixinCookRole cook;

	public EventLog log = new EventLog();
    private String name = "Cashier";
	public List<CustomerBill> bills = Collections.synchronizedList(new ArrayList<CustomerBill>());
	public List<MarketBill> marketBills = Collections.synchronizedList(new ArrayList<MarketBill>());
	public static Menu menu = new Menu();
	public YixinCashierGui cashierGui = null;
	public double money;
	
	public YixinCashierRole(PersonAgent p, YixinRestaurant r) {
		super(p);
		this.restaurant = r;
		money = 130.0;
	}
	
	public void setGui(YixinCashierGui g) {
		cashierGui = g;
	}
	
	public String getName() {
		return name;
	}
	
	// Messages
	public void msgComputeBill(YixinWaiterRole w, YixinCustomerRole c, String choice) {
		log.add(new LoggedEvent("Received ComputeBill from waiter. Choice = "+ choice));
		print("Bill Request received");
		bills.add(new CustomerBill(w,c,choice));
		stateChanged();
	}
	
	public void msgHereIsThePayment(YixinCustomerRole c, double check, double cash) {
		log.add(new LoggedEvent("Received HereIsTheCheck from customer. Check = "+ check + " Payment = "+ cash));
		print("Payment received");
		for (CustomerBill bill : bills)
			if (bill.customer == c){
				bill.cash = cash;
				bill.price  = check;
				bill.state = CustomerBill.BillState.ReturnedFromCustomer;
				stateChanged();
			}
	}
	
	public void msgHereIsTheBill(Market m, double bill, Map<String, Double> price_list){
		log.add(new LoggedEvent("Received HereIsTheBill from market. Bill = "+ bill));
		print("Market bill received with amount of " + bill);
		marketBills.add(new MarketBill(m, bill, price_list));
		stateChanged();
	}
	
	public void msgHereIsTheChange(Market m, double change){
		print("Market change received with amount of " + change);
		money += change;
		for (MarketBill bill : marketBills){
			if (bill.market == m)
				bill.state = MarketBill.BillState.changeReceived;
		}
		stateChanged();
	}
	
	public void msgHereIsTheInvoice(Market m, List<Item> invoice) {
		for (MarketBill bill : marketBills){
			if (bill.market == m)
				bill.state = MarketBill.BillState.invoiceReceived;
		}
		stateChanged();		
	}

	/**
	 * Scheduler.  Determine what action is called for, and do it.
	 */
	public boolean pickAndExecuteAnAction() {
		try{
			for (CustomerBill bill : bills){
				if (bill.state == CustomerBill.BillState.NotComputed){
					computeBill(bill);
					return true;
				}
			}
			for (CustomerBill bill : bills){
				if (bill.state == CustomerBill.BillState.ReturnedFromCustomer){
					makeChange(bill);
					bills.remove(bill);
					return true;
				}
			}
			if (money > 0){
				for (MarketBill bill : marketBills)
					if (bill.state == MarketBill.BillState.invoiceReceived){
						payMarketBill(marketBills.get(0));
						return true;
					}
			}
			for (MarketBill bill : marketBills)
				if (bill.state == MarketBill.BillState.changeReceived){
					cook.msgOrderFinished();
					marketBills.remove(bill);
					return true;
				}
		}
		catch(ConcurrentModificationException e){
			return false;
		}

		return false;
		//we have tried all our rules and found
		//nothing to do. So return false to main loop of abstract agent
		//and wait.
	}

	// Actions

	private void computeBill(CustomerBill bill) {
		print("The Bills is computed.");
		bill.state = CustomerBill.BillState.None;
		bill.waiter.msgHereIsTheCheck(bill.price, bill.customer);
	}

	private void makeChange(CustomerBill bill) {
		if(bill.cash - bill.price < 0){
			print("Customer DO NOT HAVE ENOUGH MONEY.");
			bill.customer.msgYouDoNotHaveEnoughMoney(bill.price - bill.cash);
			money += bill.cash;
			print("Remaining money is " + money);
			return;
		}<commit_msg>bank restaurant interaction in progress<commit_after>package city.restaurant.yixin;

import java.util.*;

import utilities.EventLog;
import utilities.LoggedEvent;
import city.*;
import city.bank.BankTellerRole;
import city.market.*;
import city.restaurant.RestaurantCashierRole;
import city.restaurant.yixin.gui.YixinCashierGui;

public class YixinCashierRole extends RestaurantCashierRole{// implements Cashier{
	public YixinRestaurant restaurant;
	public YixinCookRole cook;
	public BankTellerRole bankTeller;
	
	public EventLog log = new EventLog();
    private String name = "Cashier";
	public List<CustomerBill> bills = Collections.synchronizedList(new ArrayList<CustomerBill>());
	public List<MarketBill> marketBills = Collections.synchronizedList(new ArrayList<MarketBill>());
	public static Menu menu = new Menu();
	public YixinCashierGui cashierGui = null;
	public double money, bankBalance, bankDebt;
	public int account_number;
	enum MoneyState{OrderedFromBank, none}
	MoneyState money_state = MoneyState.none;
	
	public YixinCashierRole(PersonAgent p, YixinRestaurant r) {
		super(p);
		this.restaurant = r;
		money = 130.0;
		bankBalance = 0;
		bankDebt = 0;
	}
	
	public void setGui(YixinCashierGui g) {
		cashierGui = g;
	}
	
	public String getName() {
		return name;
	}
	
	// Messages
	public void msgComputeBill(YixinWaiterRole w, YixinCustomerRole c, String choice) {
		log.add(new LoggedEvent("Received ComputeBill from waiter. Choice = "+ choice));
		print("Bill Request received");
		bills.add(new CustomerBill(w,c,choice));
		stateChanged();
	}
	
	public void msgHereIsThePayment(YixinCustomerRole c, double check, double cash) {
		log.add(new LoggedEvent("Received HereIsTheCheck from customer. Check = "+ check + " Payment = "+ cash));
		print("Payment received");
		for (CustomerBill bill : bills)
			if (bill.customer == c){
				bill.cash = cash;
				bill.price  = check;
				bill.state = CustomerBill.BillState.ReturnedFromCustomer;
				stateChanged();
			}
	}
	
	public void msgHereIsTheBill(Market m, double bill, Map<String, Double> price_list){
		log.add(new LoggedEvent("Received HereIsTheBill from market. Bill = "+ bill));
		print("Market bill received with amount of " + bill);
		marketBills.add(new MarketBill(m, bill, price_list));
		stateChanged();
	}
	
	public void msgHereIsTheChange(Market m, double change){
		print("Market change received with amount of " + change);
		money += change;
		for (MarketBill bill : marketBills){
			if (bill.market == m)
				bill.state = MarketBill.BillState.changeReceived;
		}
		stateChanged();
	}
	
	public void msgHereIsTheInvoice(Market m, List<Item> invoice) {
		for (MarketBill bill : marketBills){
			if (bill.market == m)
				bill.state = MarketBill.BillState.invoiceReceived;
		}
		stateChanged();		
	}

	/**
	 * Scheduler.  Determine what action is called for, and do it.
	 */
	public boolean pickAndExecuteAnAction() {
		try{
			for (CustomerBill bill : bills){
				if (bill.state == CustomerBill.BillState.NotComputed){
					computeBill(bill);
					return true;
				}
			}
			for (CustomerBill bill : bills){
				if (bill.state == CustomerBill.BillState.ReturnedFromCustomer){
					makeChange(bill);
					bills.remove(bill);
					return true;
				}
			}
			if (money > 0){
				for (MarketBill bill : marketBills)
					if (bill.state == MarketBill.BillState.invoiceReceived){
						payMarketBill(marketBills.get(0));
						return true;
					}
			}
			for (MarketBill bill : marketBills)
				if (bill.state == MarketBill.BillState.changeReceived){
					cook.msgOrderFinished();
					marketBills.remove(bill);
					return true;
				}
			if (money > 0 && bankDebt > 0){
				
				return true;
			}
			else if (money < 0){
				bankTeller.msgWiredTransaction(c, request, amount);
			}
				
		}
		catch(ConcurrentModificationException e){
			return false;
		}

		return false;
		//we have tried all our rules and found
		//nothing to do. So return false to main loop of abstract agent
		//and wait.
	}

	// Actions

	private void computeBill(CustomerBill bill) {
		print("The Bills is computed.");
		bill.state = CustomerBill.BillState.None;
		bill.waiter.msgHereIsTheCheck(bill.price, bill.customer);
	}

	private void makeChange(CustomerBill bill) {
		if(bill.cash - bill.price < 0){
			print("Customer DO NOT HAVE ENOUGH MONEY.");
			bill.customer.msgYouDoNotHaveEnoughMoney(bill.price - bill.cash);
			money += bill.cash;
			print("Remaining money is " + money);
			return;
		}
{'fraction_non_alphanumeric': 0.11070588235294118, 'fraction_numerical': 0.002235294117647059, 'mean_word_length': 3.9338363319791063, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3625950', 'n_tokens_mistral': 3200, 'n_tokens_neox': 2658, 'n_words': 694}