import 'dart:convert';

import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/model/product.dart';
import 'package:aitrainer_app/service/api.dart';

class ProductApi {
  final APIClient _client = new APIClient();

  Future<List<Product>> getProducts() async {
    final body = await _client.get("product/", "");
    final Iterable json = jsonDecode(body);
    final List<Product> products = json.map((product) => Product.fromJson(product)).toList();
    Cache().setProducts(products);
    return products;
  }
}
