package de.siphalor.was.game;

import org.jetbrains.annotations.NotNull;

import java.util.Locale;

/**
 * Represents a transaction.
 */
public class Transaction {
	/**
	 * The {@link Type} of this transaction
	 */
	private final Type type;
	/**
	 * The money change of this transaction
	 */
	private final int change;
	/**
	 * An optional translation key for a product. Might be empty
	 */
	private final String productKey;

	/**
	 * Constructs a new transaction.
	 * @param type The type
	 * @param change The money change of this transaction
	 * @param productKey A translation key for a product
	 */
	public Transaction(@NotNull Type type, int change, @NotNull String productKey) {
		this.type = type;
		this.change = change;
		this.productKey = productKey;
	}

	/**
	 * Gets the type.
	 * @return The type
	 */
	@NotNull
	public Type getType() {
		return type;
	}

	/**
	 * Gets the money change
	 * @return The change
	 */
	public int getChange() {
		return change;
	}

	/**
	 * Gets the product translation key.
	 * @return The translation key or <code>""</code> if none is present
	 */
	@NotNull
	public String getProductKey() {
		return productKey;
	}

	/**
	 * Represents the type of a transaction:
	 * <ul>
	 *     <li><code>ABANDON</code>: Abandoned a quest</li>
	 *     <li><code>DESTROY</code>: destroyed a product</li>
	 *     <li><code>MOVE</code>: Moved a product</li>
	 *     <li><code>NOOP</code>: For internal use. To be used with a change of <code>0</code></li>
	 *     <li><code>DELIVER</code>: Delivered a product</li>
	 *     <li><code>STORE</code>: Stored a product</li>
	 *     <li><code>RESOLVE</code>: Resolved two quests against each other</li>
	 * </ul>
	 */
	public enum Type {
		ABANDON, DESTROY, MOVE, NOOP, DELIVER, STORE, RESOLVE;

		/**
		 * Gets the translation key for this type
		 * @return The translation key
		 */
		@NotNull
		public String getTranslationKey() {
			return "game.balance.history.type." + name().toLowerCase(Locale.ENGLISH);
		}
	}
}
