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:betting/view/mobile/find/list_regions/detail_regions/detail_matches_in_regions/stats_matches_regions/stats_matches_regions_controller.dart';
import 'package:get/get.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() {
    // TODO: implement onInit
    super.onInit();
    match.value = Get.arguments;
    getMatchEvent(match.value.sId!);
    getStats(match.value.sId!);
  }

  /// todo: get event of match
  void getMatchEvent(String matchId) async {
    _repo.getMatchEvent(matchId).then((value) {
      if (value.state == Status.SUCCESS) {
        listEvent.value = value.object!;
      }
    });
  }

  /// todo: Method get stats of summary screen
  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();
      }
    });
  }
}
