import 'package:bloc/bloc.dart';
import 'package:dio/dio.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
import 'package:hoshan/data/model/report_model.dart';
import 'package:hoshan/data/repository/auth_repository.dart';
import 'package:shamsi_date/shamsi_date.dart';

part 'report_pi_coin_state.dart';

class ReportPiCoinCubit extends Cubit<ReportPiCoinState> {
  ReportPiCoinCubit() : super(ReportPiCoinInitial());

  Future getReport({final Jalali? startDate}) async {
    emit(ReportPiCoinLoading());
    try {
      final response = await AuthRepository.getReportCoin(startDate: startDate);

      if (response.report != null && response.report!.isNotEmpty) {
        emit(ReportPiCoinSuccess(points: response.report!));
      } else {
        emit(ReportPiCoinEmpty());
      }
    } on DioException catch (e) {
      emit(ReportPiCoinFail());
      if (kDebugMode) {
        print('Dio Error is: $e');
      }
    }
  }
}
