import 'package:get/get_rx/src/rx_types/rx_types.dart';
import 'package:mypoint_flutter_app/networking/restful_api_request.dart';
import 'package:mypoint_flutter_app/screen/game/models/game_bundle_item_model.dart';

import '../../base/restful_api_viewmodel.dart';
import '../../configs/constants.dart';

class GameTabViewModel extends RestfulApiViewModel {
  final RxList<GameBundleItemModel> games = <GameBundleItemModel>[].obs;
  var turnsNumberText = "".obs;
  var isLoading = false.obs;
  var errorMessage = "".obs;

  void getGames() {
    isLoading(true);
    client.getGames().then((value) {
      if (!value.isSuccess) {
        errorMessage.value = value.errorMessage ?? Constants.commonError;
      } else {
        games.value = value.data?.games ?? [];
        turnsNumberText.value = value.data?.turnsNumberText ?? "";
      }
      isLoading(false);
    });
  }
}