import 'package:uuid/uuid.dart';

class Transaction {
  String uuid;
  DateTime date;
  String category;
  String description;
  String account;
  double value;

  Transaction({
    required this.uuid,
    required this.date,
    required this.category,
    required this.description,
    required this.account,
    required this.value
  });

  factory Transaction.fromJson(Map<String, dynamic> json) {
    return Transaction(
      uuid: json['uuid'] ?? const Uuid().v8(),
      date: DateTime.parse(json['date']),
      category: json['category'],
      description: json['description'],
      account: json['account'],
      value: double.parse(json['value']),
    );
  }

  Map<String, String> toJson() => {
    'uuid': uuid,
    'date': date.toIso8601String(),
    'category': category,
    'description': description,
    'account': account,
    'value': value.toString(),
  };
}