/*This code was generated using the UMPLE modeling language!
 Date of generation: 2008/07/30 12:41:45*/
/*This class drives: */

package BankingSystem.core;

import java.util.*;
import BankingSystem.*;
import BankingSystem.json.*;

public class DebitCard extends ReusableFinancialInstrument {
  //Class datatypes

  //Class association variables
  private List<BankAccount> bankAccounts;

  //Registry of our system.
  BankingSystemRegistry registry = BankingSystemRegistry.getInstance();

  //Constructor
  public DebitCard(String aNumber, String aPIN,
    FinancialInstitution aFinancialInstitution, Currency aCurrency,
    ArrayList<BankAccount> bankAccounts) {
    super(aNumber, aPIN, aFinancialInstitution, aCurrency);
    this.bankAccounts = bankAccounts;

  }

  public List<BankAccount> getBankAccounts() {
    return bankAccounts;
  }

  public BankAccount addBankAccount(String aAccountNumber, String aBalance,
    Float aOverdraftOrCreditLimit, Branch aBranch) {
    BankAccount newBankAccount;
    newBankAccount =
      new BankAccount(aAccountNumber, aBalance, aOverdraftOrCreditLimit,
        aBranch);
    if (!bankAccounts.contains(newBankAccount)) {
      registry.add(newBankAccount);
      bankAccounts.add(newBankAccount);
    }
    return newBankAccount;
  }

  public BankAccount addBankAccount(BankAccount aBankAccount) {
    if (!bankAccounts.contains(aBankAccount))
      bankAccounts.add(aBankAccount);
    return aBankAccount;
  }

  public void delete() {
  }

  public void deleteBankAccount(BankAccount aBankAccount) {

    if (bankAccounts.contains(aBankAccount)) {
      bankAccounts.remove(aBankAccount);

      //registry.removeObj(registry.getKey(aBankAccount));
    } else
    //Throw an UmpleException .. to be implemented.
    {
    }
  }

  public boolean areManyEndsNull() {
    return true;
  }

  /***********************************
   * Returns the attribute list along with the  
   * class ID in JSON format.
   ***********************************/
  public JSONObject getAttributes() throws JSONException {
    JSONObject obj = new JSONObject();
    obj.put("CLASS_ID", registry.getKey(this));
    return obj;
  }

}