from datetime import date

import pytest

from smartwallet.factory import BudgetFactory


def test_create_transaction_requires_name() -> None:
    with pytest.raises(ValueError, match="Transaction name cannot be empty"):
        BudgetFactory.create_transaction("", 10)


def test_create_transaction_requires_numeric_amount() -> None:
    with pytest.raises(ValueError, match="Amount must be a number"):
        BudgetFactory.create_transaction("Salary", "abc")


def test_create_transaction_rejects_zero_amount() -> None:
    with pytest.raises(ValueError, match="Transaction amount cannot be 0"):
        BudgetFactory.create_transaction("Salary", 0)


def test_create_transaction_defaults_date() -> None:
    transaction = BudgetFactory.create_transaction("Salary", 100)

    assert transaction.transaction_date == date.today().isoformat()


def test_create_transaction_validates_date() -> None:
    with pytest.raises(ValueError, match="Invalid date format"):
        BudgetFactory.create_transaction("Salary", 100, "2023/10/01")


def test_create_category_requires_name() -> None:
    with pytest.raises(ValueError, match="Category name cannot be empty"):
        BudgetFactory.create_category(" ")
