import 'dart:convert';

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

import '../model/sport.dart';

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

  Future<List<Sport>> getSports() async {
    final body = await _client.get("sports/", "");
    final Iterable json = jsonDecode(body);
    final List<Sport> sports = json.map((sport) => Sport.fromJson(sport)).toList();
    Cache().setSports(sports);
    return sports;
  }
}
