package de.siphalor.was.game;

import de.siphalor.was.content.product.Product;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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<Transaction> history = new ConcurrentLinkedQueue<>();

	public Transaction add(@NotNull Transaction.Type type, int change, @Nullable Product product) {
		return add(new Transaction(type, change, product != null ? product.getTranslationKey() : ""));
	}

	public Transaction add(@NotNull Transaction transaction) {
		history.add(transaction);

		budget += transaction.getChange();

		if (transaction.getChange() < 0) {
			totalLoss -= transaction.getChange();
		} else {
			totalIncome += transaction.getChange();
		}
		return transaction;
	}

	@NotNull
	public Queue<Transaction> getHistory() {
		return history;
	}

	public int getBudget() {
		return budget;
	}

	public int getTotalIncome() {
		return totalIncome;
	}

	public int getTotalLoss() {
		return totalLoss;
	}

}
