from __future__ import annotations

from dataclasses import dataclass, field
from datetime import date

from smartwallet.model.base import BudgetComponent


@dataclass
class Transaction(BudgetComponent):
    amount: float = 0.0
    transaction_date: str = field(default_factory=lambda: date.today().isoformat())

    def get_balance(self) -> dict[str, float]:
        if self.amount >= 0:
            return {"income": self.amount, "expense": 0.0, "total": self.amount}
        return {"income": 0.0, "expense": self.amount, "total": self.amount}

    def to_dict(self) -> dict[str, object]:
        return {
            "type": "transaction",
            "id": self.id,
            "name": self.name,
            "amount": self.amount,
            "transaction_date": self.transaction_date,
            "created_at": self.created_at,
        }
