mirrored_repositories/Expenses_Tracker_App/packages/expense_repository/lib/src
import 'package:cloud_firestore/cloud_firestore.dart';

class ExpenseEntity {
  String? userId;
  String? howExpense;
  String expenseId;
  String? categoryId;
  String? currency;
  String categoryImagePath;
  String categoryName;
  String? explain;
  DateTime date;
  int amount;

  ExpenseEntity({
    this.userId,
    this.explain,
    this.categoryId,
    this.howExpense,
    this.currency,
    required this.categoryImagePath,
    required this.expenseId,
    required this.categoryName,
    required this.date,
    required this.amount,
  });

  Map<String, dynamic> toDocument() {
    return {
      'currency': currency,
      'categoryId': categoryId,
      'explain': explain,
      'userId': userId,
      'howExpense': howExpense,
      'expenseId': expenseId,
      'categoryName': categoryName,
      'categoryImagePath': categoryImagePath,
      'date': Timestamp.fromDate(date),
      'amount': amount,
    };
  }

  static ExpenseEntity fromDocument(Map<String, dynamic> doc) {
    return ExpenseEntity(
      currency: doc['currency'] ?? '',
      categoryId: doc['categoryId'] ?? '',
      explain: doc['explain'] ?? '',
      userId: doc['userId'] ?? '',
      howExpense: doc['howExpense'] ?? '',
      expenseId: doc['expenseId'] ?? '',
      categoryName: doc['categoryName'] ?? '',
      categoryImagePath: doc['categoryImagePath'] ?? '',
      date: (doc['date'] as Timestamp?)?.toDate() ?? DateTime.now(),
      amount: doc['amount'] ?? 0,
    );
  }
}
