import 'package:bloc/bloc.dart';
import 'package:meta/meta.dart';

import '../../../../core/application/di/injectable.dart';
import '../notification_entity.dart';
import '../notification_repository.dart';

part 'notifications_event.dart';
part 'notifications_state.dart';

class NotificationsBloc extends Bloc<NotificationsEvent, NotificationsState> {
  NotificationsBloc() : super(NotificationsState()) {
    on<NotificationsInitEvent>(_onNotificationsInit);
  }

  void _onNotificationsInit(NotificationsInitEvent event, emit) async {
    var notifications =
        await getIt<NotificationsRepository>().fetchNotifications();

    emit(state.copyWith(
      notifications: notifications,
    ));
  }
}
