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/competition_standings/competition_standings_model.dart';

class CompetitionStandingsRepo {
  Future<ResponseData<List<CompetitionStandings>>> getListCompetitionStandings(String competitionId, String? teamId) async {
    ResponseData<List<CompetitionStandings>> streamEvent = ResponseData(state: Status.LOADING);

    var param = <String, dynamic>{};
    ApiResponse<BaseModel> apiResponse =
    await ApiService('${ApiConstants.API_COMPETITION_STANDING}?competitionId=$competitionId&teamId=$teamId', request: param)
        .request(Request.GET);

    if (apiResponse.status == Status.SUCCESS) {
      List<CompetitionStandings> data = [];
      apiResponse.data?.data.map((e) {
        data.add(CompetitionStandings.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;
  }
}