import 'package:boilerplate/core/utils/shared_preferences_util.dart';
import 'package:boilerplate/presentation/bloc/notification/notification_count/notification_count_state.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:injectable/injectable.dart';

@injectable
class NotificationCountCubit extends Cubit<NotificationCountState> {
  @factoryParam
  final SharedPreferencesUtil _pref;

  NotificationCountCubit(this._pref) : super(InitialState());

  getNotificationCount() {
    final count = _pref.getInt(SharedPreferencesUtil.keyNotificationCount);

    if (count != null && count > 0) {
      emit(HaveNotificaitonCountState(count));
    } else {
      emit(NotHaveNotificationCountState());
    }
  }

  clearNotificationCount() {
    _pref.putInt(SharedPreferencesUtil.keyNotificationCount, 0);

    getNotificationCount();
  }
}
