import 'package:dio/dio.dart';

import '../../../../core/error/custom_error.dart';
import '../../../../core/resources/data_state.dart';
import '../../domain/entities/leaderboard.dart';
import '../../domain/repository/ranked_repository.dart';
import '../data_source/remote/ranked_api_provider.dart';

class RankedRepositoryImpl extends RankedRepository {
  final RankedApiProvider api;
  RankedRepositoryImpl(this.api);

  @override
  Future<DataState<Leaderboard>> getLeaderboard() async {
    final Response res = await api.getLeaderboard();
    if (res.statusCode == 200) {
      return DataSuccess(
          Leaderboard.fromJson(Map<String, dynamic>.from(res.data as Map)));
    }
    return DataError(errorConvertor(res.statusCode, null));
  }
}
