from savingsaccount import SavingsAccount


class CreditAccount(SavingsAccount):
    def withdraw(self, amount):
        if amount < 0:
            raise ValueError(f"Account number {self.number}: cannot withdraw a negative amount.")
        self.balance -= amount

    def get_interests(self):
        if self.balance < 0:
            return 0
        return self.balance * self.interest_rate


if __name__ == "__main__":
    credit_account = CreditAccount("2222-CRED-0001", 1000, 0.05)
    credit_account.capitalize()  # stan konta dodatni, doliczamy dodatnie odsetki
    print(credit_account)  # 1
    credit_account.withdraw(2000)  # stan konta ujemny
    print(credit_account)  # 2
    credit_account.capitalize()  # stan konta ujemny, get_interests() zwróci 0, stan konta się nie zmieni
    print(credit_account)  # 3
