import 'package:betting/commom/constants/api_constant.dart';
import 'package:betting/data/base_service/api_response.dart';
import 'package:betting/data/base_service/api_service.dart';
import 'package:betting/data/base_service/respone_data.dart';
import 'package:betting/data/model/base_model.dart';
import 'package:betting/data/model/res/goal_score/goal_score_model.dart';

class GoalScorerRepo {
  Future<ResponseData<List<GoalScore>>> getListTopScore(int? page, int? size, String? competitionId, String? seasonId, String? teamId) async {
    ResponseData<List<GoalScore>> streamEvent = ResponseData(state: Status.LOADING);
    var param = <String, dynamic>{};
    var urlApi = "${ApiConstants.API_GOAL_SCORER}?page=$page&size=$size&competitionId=$competitionId&seasonId=$seasonId&teamId=$teamId";
    ApiResponse<BaseModel> apiResponse =
    await ApiService(urlApi, request: param)
        .request(Request.GET);

    if (apiResponse.status == Status.SUCCESS) {
      List<GoalScore> data = [];
      apiResponse.data?.data.map((e) {
        data.add(GoalScore.fromJson(e));
      }).toList();
      streamEvent = ResponseData(state: Status.SUCCESS, object: data);

    }

    if (apiResponse.status == Status.ERROR) {
      streamEvent = ResponseData(
          state: Status.ERROR,
          errorCode: apiResponse.error,
          message: apiResponse.error?.message);
    }
    return streamEvent;
  }
}