#include <iostream>
#include <string>

// Struct representing the account owner
struct Owner {
  std::string name;
  std::string address;
};

// BankAccount class with dynamic reference to an Owner
class BankAccount {
public:
  int accountNumber;
  double balance;
  Owner* owner; // Dynamic reference to an owner

  // Constructor with dynamic owner
  BankAccount(int accNum, double bal, std::string name, std::string address)
      : accountNumber(accNum), balance(bal) {
      owner = new Owner;
      owner->name = name;
      owner->address = address;
  }

  // // Copy constructor for deep copy
  // BankAccount(const BankAccount& other)
  //   : accountNumber(other.accountNumber), balance(other.balance) {
  //   owner = new Owner;  // Deep copy of owner
  //   owner->address = other.owner->address;
  //   owner->name = other.owner->name;
  // }

  // // Assignment operator for deep copy
  // BankAccount& operator=(const BankAccount& other) {
  //   if (this != &other) {
  //     accountNumber = other.accountNumber;
  //     balance = other.balance;

  //     delete owner;  // Clean up existing owner
  //     owner = new Owner;  // Deep copy of new owner
  //     owner->address = other.owner->address;
  //     owner->name = other.owner->name;
  //   }
  //   return *this;
  // }

  // Destructor to clean up dynamic memory
  ~BankAccount() {
    delete owner;
  }

  // Display account information
  void displayAccountInfo() const {
    std::cout << "Account Number: " << accountNumber << std::endl;
    std::cout << "Balance: $" << balance << std::endl;
    std::cout << "Owner Name: " << owner->name << std::endl;
    std::cout << "Owner Address: " << owner->address << std::endl;
  }
};

int main() {
  // Create a bank account with the owner
  BankAccount account1(101, 1000.50, "John doe", "123 example st.");

  // Copy the account to a new object
  BankAccount account2 = account1;

  // update the original account name
  account1.owner->name = "john deere";

  // Display account1 information
  account1.displayAccountInfo();

  // Display account2 information
  std::cout << "\nCopied account information:\n";
  account2.displayAccountInfo();
}
