#include <iostream>
#include <iomanip>

#include "./DividendStock.h"

using namespace std;

// Constructs a new dividend stock with the given symbol and no shares.
DividendStock::DividendStock(string symbol, double share_price) {
  symbol_ = symbol;
  share_price_ = share_price;
  cost_ = 0.0;
  shares_ = 0;
  dividends_ = 0.0;
}

// Gets the stock symbol.
string DividendStock::get_symbol() const {
  return symbol_;
}

// Returns the total number of shares purchased.
int DividendStock::get_shares() const {
  return shares_;
}

// Returns the price per share of this asset.
double DividendStock::get_share_price() const {
  return share_price_;
}

// Sets the current share price of this asset.
void DividendStock::set_share_price(double share_price) {
  share_price_ = share_price;
}

// Returns this asset's total cost spent on all shares.
double DividendStock::GetCost() const {
  return cost_;
}

// Returns the market value of this stock, which is the total number
// of shares times the share price, plus dividends
double DividendStock::GetMarketValue() const {
  return shares_ * share_price_ + dividends_;
}

// Returns the profit earned on shares of this asset.
double DividendStock::GetProfit() const {
  return GetMarketValue() - GetCost();
}

// Returns the total amount of dividends paid on this stock.
double DividendStock::GetDividends() const {
  return dividends_;
}

// Records a purchase of the given number of shares of stock at the
// given price per share.
void DividendStock::Purchase(int shares, double share_price) {
  shares_ += shares;
  cost_ += shares * share_price;
}

// Records a dividend of the given amount per share.
void DividendStock::PayDividend(double amount_per_share) {
  dividends_ += amount_per_share * shares_;
}

// Print out the Dividendstock information.
void DividendStock::Print() const {
  cout << "DividendStock (" << get_symbol() << "):" << endl;
  cout << "  value: $" << setw(7) << GetMarketValue() << endl;
  cout << "   cost: $" << setw(7) << GetCost() << endl;
  cout << " profit: $" << setw(7) << GetProfit() << endl;
}