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


class CategoriesRepo {
  Future<ResponseData<List<Categories>>> getAllCategories() async {
    ResponseData<List<Categories>> streamEvent = ResponseData(state: Status.LOADING);

    var param = <String, dynamic>{};
    ApiResponse<BaseModel> apiResponse =
    await ApiService(ApiConstants.API_CATEGORIES, request: param)
        .request(Request.GET);

    if (apiResponse.status == Status.SUCCESS) {
      List<Categories> items = <Categories>[];
      apiResponse.data?.data.forEach((v){
        items.add(Categories.fromJson(v));
      });
      if(items.isNotEmpty) {
        streamEvent = ResponseData(state: Status.SUCCESS, object: items);
      } else {
        streamEvent = ResponseData(
            state: Status.ERROR,
            errorCode: apiResponse.error,
            message: "");
      }
    }
    if (apiResponse.status == Status.ERROR) {
      streamEvent = ResponseData(
          state: Status.ERROR,
          errorCode: apiResponse.error,
          message: apiResponse.error?.message);
    }
    return streamEvent;
  }


}