import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../../core/network/dio_client.dart';
import '../../data/datasources/leaderboard_remote_datasource.dart';
import '../../data/repositories/leaderboard_repository_impl.dart';
import 'leaderboard_state.dart';

class LeaderboardCubit extends Cubit<LeaderboardState> {
  final LeaderboardRepositoryImpl _repo;

  LeaderboardCubit()
      : _repo = LeaderboardRepositoryImpl(
            LeaderboardRemoteDatasource(DioClient.instance)),
        super(const LeaderboardLoading());

  Future<void> loadLeaderboard() async {
    emit(const LeaderboardLoading());
    try {
      final entries = await _repo.getLeaderboard();
      emit(LeaderboardLoaded(entries));
    } catch (e) {
      emit(LeaderboardError(e.toString()));
    }
  }
}