from smartwallet.model import Category, Transaction


def test_transaction_balance_income() -> None:
    transaction = Transaction(name="Salary", amount=100.0)

    assert transaction.get_balance() == {
        "income": 100.0,
        "expense": 0.0,
        "total": 100.0,
    }


def test_transaction_balance_expense() -> None:
    transaction = Transaction(name="Rent", amount=-50.0)

    assert transaction.get_balance() == {
        "income": 0.0,
        "expense": -50.0,
        "total": -50.0,
    }


def test_category_balance_recursive() -> None:
    root = Category(name="Root")
    home = Category(name="Home")
    root.add(home)

    home.add(Transaction(name="Rent", amount=-200.0))
    root.add(Transaction(name="Salary", amount=500.0))

    balance = root.get_balance()

    assert balance["income"] == 500.0
    assert balance["expense"] == -200.0
    assert balance["total"] == 300.0
