import 'package:betting/data/base_service/api_response.dart';
import 'package:betting/data/model/res/matches/matches.dart';
import 'package:betting/data/repository/matches/matches_repo.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';

class ResultsScreenController extends GetxController {
  MatchesRepo matchesRepo = MatchesRepo();
  var listMatchesFavourite = <ItemsMatches>[].obs;
  var outputTimeFormat = DateFormat('HH:mm');
  var outputDateFormat = DateFormat('dd/MM/yyyy');
  RxBool isLoading = false.obs;
  @override
  void onInit()  {
    getListMatchesOnTeamFavouriteResult();
    super.onInit();
  }
  getListMatchesOnTeamFavouriteResult() async{
    await matchesRepo.getListMatchesFavourites('FINISHED').then((value) {
      if(value.state == Status.SUCCESS){
        listMatchesFavourite.value = value.object!;
      }
    },
    );
    isLoading.value = true;
    update();
  }

  /// Method delete match favourite
  void delMatchFavourite(String matchId) async{
    matchesRepo.deleteMatchesFavorites(matchId).then((value) {
      if(value.state == Status.SUCCESS) {
        print('Delete match favourite successfully!');
        getListMatchesOnTeamFavouriteResult();
      } else {
        print('Delete failed!');
      }
    });
  }
}
