#include <iostream>
#include <vector>

#include "account.hpp"

using bank::Account, bank::ChildAccount;
using std::cout, std::endl, std::vector;

int main() {
  Account a {"Gerald"};
  cout << a << endl;
  a.deposit(2000);
  cout << a << endl;
  cout << "attempting to withdraw 2500 cents\n";
  a.withdraw(2500);
  cout << a << endl;

  ChildAccount ca {"Eric"};
  ca.deposit(5000);
  cout << ca << endl;
  cout << "attempting to withdraw 100000 leads to actually withdrawing ";
  cout << ca.withdraw(100000) << endl;
  cout << ca << endl;

  cout << "\nworking with a `ChildAccount` pointed to by an `Account*`\n";
  ChildAccount ca2 {"Mary"};
  Account* ap = &ca2;
  cout << *ap << endl;
  ap->deposit(2000);
  cout << *ap << endl;
  cout << "attempting to withdraw 2500 leads to actually withdrawing ";
  cout << ap->withdraw(2500) << endl;  // requires `virtual` in base class
  cout << *ap << endl << endl;

  vector<Account*> accounts{&a, &ca, &ca2};  // polymorphism ftw!
  for (auto& account : accounts) {
    cout << "got " << account->withdraw(100) << " from " << *account << endl;
  }
}
