from dataclasses import dataclass
from decimal import Decimal

NEEDS_CATEGORIES = [
    'Housing', 'Utilities', 'Groceries', 'Transportation', 'Healthcare', 'Debt Payments',
]
WANTS_CATEGORIES = [
    'Dining', 'Entertainment', 'Shopping', 'Subscriptions', 'Personal Care',
]


@dataclass
class BudgetRecommendation:
    category_name: str
    suggested_amount: Decimal
    bucket: str  # 'needs' | 'wants' | 'savings'


def fifty_thirty_twenty(monthly_income: Decimal) -> list[BudgetRecommendation]:
    """Return 50/30/20 budget recommendations for the given monthly income.

    Defines the BudgetRecommendation interface contract — Story 10.7's
    from_history() must return the same type.
    """
    needs_per_cat = (
        (monthly_income * Decimal('0.50') / len(NEEDS_CATEGORIES))
        .quantize(Decimal('0.01'))
    )
    wants_per_cat = (
        (monthly_income * Decimal('0.30') / len(WANTS_CATEGORIES))
        .quantize(Decimal('0.01'))
    )
    savings_total = (monthly_income * Decimal('0.20')).quantize(Decimal('0.01'))

    recs: list[BudgetRecommendation] = []
    for name in NEEDS_CATEGORIES:
        recs.append(BudgetRecommendation(name, needs_per_cat, 'needs'))
    for name in WANTS_CATEGORIES:
        recs.append(BudgetRecommendation(name, wants_per_cat, 'wants'))
    recs.append(BudgetRecommendation('Savings', savings_total, 'savings'))
    return recs
