Purchase.java

package edu.ntnu.idi.idatt.model.transaction;

import edu.ntnu.idi.idatt.model.player.Player;
import edu.ntnu.idi.idatt.model.portfolio.Share;
import edu.ntnu.idi.idatt.service.transaction.PurchaseCalculator;

/**
 * Purchase class
 *
 * <p>
 * Manages player state at purhcasing stocks.
 * Collected as detail in TransactionArchive.
 * </p>
 * 
 * @see Transaction
 * @see TransactionArchive
 */
public class Purchase extends Transaction {
  /**
   * Constructor for a Purchase
   *
   * @param share - The purchased share.
   * @param week  - The current week
   */
  public Purchase(Share share, int week) {
    super(share, week, new PurchaseCalculator(share));
  }

  /**
   * @see Transaction
   * @param player - The player that does the transaction
   */
  @Override
  public void commit(Player player) {
    player.withdrawMoney(this.getCalculator().calculateTotal());
    player.getPortfolio().addShare(this.getShare());
    player.getTransactionArchive().add(this);

    this.commited = true;
  }

}