from smartwallet.model import Category, Transaction


def test_category_remove_child_by_id() -> None:
    root = Category(name="Root")
    keep = Transaction(name="Salary", amount=100.0)
    remove = Transaction(name="Rent", amount=-50.0)

    root.add(keep)
    root.add(remove)

    root.remove(remove.id)

    assert [child.id for child in root.children] == [keep.id]


def test_category_to_dict_serializes_children() -> None:
    root = Category(name="Root")
    child = Transaction(name="Salary", amount=100.0)
    root.add(child)

    serialized = root.to_dict()

    assert serialized["type"] == "category"
    assert serialized["name"] == "Root"
    assert serialized["children"][0]["type"] == "transaction"
    assert serialized["children"][0]["name"] == "Salary"


def test_transaction_to_dict_serializes_fields() -> None:
    transaction = Transaction(name="Salary", amount=100.0)
    serialized = transaction.to_dict()

    assert serialized["type"] == "transaction"
    assert serialized["name"] == "Salary"
    assert serialized["amount"] == 100.0
