import 'package:krezus/repositories/json/models/json.dart';
import 'package:krezus/repositories/transactions/models/transaction.dart';

class Transactions implements Json {
  List<Transaction> transactions;

  Transactions({
    this.transactions = const [],
  });
  
  @override
  Map<String, dynamic> toJson() => {
    'transactions': transactions.map((transaction) => transaction.toJson()).toList(),
  };
  
  @override
  String getJsonFileName() {
    return 'transactions.json';
  }
}

class TransactionsFactory implements JsonFactory<Transactions> {
  @override
  Transactions fromJson(Map<String, dynamic> json) {
    return Transactions(
      transactions: List<Transaction>.from(json['transactions']?.map((transaction) => Transaction.fromJson(transaction))),
    );
  }
}