38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
from notification_service import send_notification
|
|
|
|
|
|
class BankAccount:
|
|
def __init__(self, owner, balance=0):
|
|
if not owner.strip():
|
|
raise ValueError("Owner is required")
|
|
if balance < 0:
|
|
raise ValueError("Initial balance cannot be negative")
|
|
self.owner = owner
|
|
self.balance = balance
|
|
|
|
def deposit(self, amount):
|
|
if amount <= 0:
|
|
raise ValueError("Deposit must be positive")
|
|
self.balance += amount
|
|
return self.balance
|
|
|
|
def withdraw(self, amount):
|
|
if amount <= 0:
|
|
raise ValueError("Withdrawal must be positive")
|
|
if amount > self.balance:
|
|
raise ValueError("Insufficient funds")
|
|
self.balance -= amount
|
|
return self.balance
|
|
|
|
def transfer(self, recipient, amount):
|
|
if recipient is self:
|
|
raise ValueError("Cannot transfer to the same account")
|
|
if amount <= 0:
|
|
raise ValueError("Transfer must be positive")
|
|
if amount > self.balance:
|
|
raise ValueError("Insufficient funds")
|
|
self.balance -= amount
|
|
recipient.balance += amount
|
|
send_notification(recipient.owner, f"Received {amount} from {self.owner}")
|
|
return self.balance
|