#pragma once
#include "Account.h"
using namespace System::Collections;

ref class Bank
{
	ArrayList^ accts;
	public:
		Bank(void);
		bool Add(Account^ pAcc)
		{
			// check if the account is already in the list
			if (accts->Contains(pAcc))
				return false;
			else
				accts->Add(pAcc);
			    return true;
		}

		bool Remove(Account^ pAcc)
		{
			// check if the account is already in the list
			if (accts->Contains(pAcc))
				{
					accts->Remove(pAcc);
					return true;
				}
			else
				return false;
		}

		// indexed property of the account number...
		property Account^ getAcct[int]
		{
			// get the account number...
			Account^ get(long number)
			{
				IEnumerator^ ie = accts->GetEnumerator();
				// iterate the array...
				while (ie->MoveNext())
				{
					// cast to the Account^ type...
					Account^ pa = dynamic_cast<Account^>(ie->Current);
					// if found...
					if (pa->AccountNumber == number)
						// return the account number...
						return pa;
				}
				throw gcnew ArgumentOutOfRangeException(L"Bad account number");
			}
		}
};
