package de.siphalor.was.game;

import de.siphalor.was.util.Pair;

import java.util.Locale;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public class Balance {
	private int budget = 0;
	private int totalIncome = 0;
	private int totalLoss = 0;
	private final Queue<Pair<Transaction, Integer>> history = new ConcurrentLinkedQueue<>();

	public void add(Transaction transaction, int change) {
		history.add(Pair.of(transaction, change));

		budget += change;

		if (change < 0) {
			totalLoss -= change;
		} else {
			totalIncome += change;
		}
	}

	public Queue<Pair<Transaction, Integer>> getHistory() {
		return history;
	}

	public int getBudget() {
		return budget;
	}

	public int getTotalIncome() {
		return totalIncome;
	}

	public int getTotalLoss() {
		return totalLoss;
	}

	public enum Transaction {
		ABANDON, DESTROY, MOVE, NOOP, DELIVER, STORE;

		public String getTranslationKey() {
			return "game.balance.history.type." + name().toLowerCase(Locale.ENGLISH);
		}
	}
}
