import 'package:betting/data/base_service/api_response.dart';
import 'package:betting/data/model/res/match_event/match_event_model.dart';
import 'package:betting/data/model/res/matches/matches.dart';
import 'package:betting/data/model/res/stats/stats.dart';
import 'package:betting/data/repository/matches/matches_repo.dart';
import 'package:get/get.dart';
import '../stats_matches_regions/stats_matches_regions_controller.dart';

class SummaryMatchesRegionsController extends GetxController {
  final MatchesRepo _repo = MatchesRepo();
  final statsController = Get.put(StatsMatchesRegionsController());
  RxList listEvent = <MatchEvent>[].obs;
  RxList listStat = <Stats>[].obs;
  var match = Matches().obs;

  @override
  void onInit() {
    super.onInit();
    match.value = Get.arguments;
    getMatchEvent(match.value.sId!);
    getStats(match.value.sId!);
  }


  void getMatchEvent(String matchId) async {
    _repo.getMatchEvent(matchId).then((value) {
      if (value.state == Status.SUCCESS) {
        listEvent.value = value.object!;
      }
    });
  }

  void getStats(String matchId) async {
    _repo.getStatsMatches(matchId).then((value) {
      if(value.state == Status.SUCCESS) {
        listStat.value = value.object!
            .where((element) =>
        element.name == 'possesion' ||
            element.name == 'shotsOnTarget' ||
            element.name == 'yellowCards' ||
            element.name == 'corners')
            .toList();
      }
    });
  }
}
