import 'dart:convert';

import 'package:firebase_database/firebase_database.dart';

import '../currency.dart';
import '../model/product_model.dart';

class ProductRepo {
  Future<List<ProductModel>> getAllProduct() async {
    List<ProductModel> productList = [];
    FirebaseDatabase.instance.ref(constUserId).child('Products').orderByKey().get().then((value) {
      for (var element in value.children) {
        ProductModel product = ProductModel.fromJson(jsonDecode(jsonEncode(element.value)));
        product.productKey = element.key;
        productList.add(product);
      }
    });
    final productsRef = FirebaseDatabase.instance.ref(constUserId).child('Products');
    productsRef.keepSynced(true);
    return productList;
  }
}
