import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/model/passo/memoranda.dart';

import '../../../../../sevices/offline/offline_passo/admin/sql_services/sql_services.dart';

part 'memoranda_admin_event.dart';
part 'memoranda_admin_state.dart';

class MemorandaAdminBloc
    extends Bloc<MemorandaAdminEvent, MemorandaAdminState> {
  MemorandaAdminBloc() : super(MemorandaAdminInitial()) {
    List<Memoranda> memo = [];
    on<LoadMemoranda>((event, emit) async {
      memo = await SQLServices.instance.readAllMemoranda();

      emit(MemorandaLoaded(memo: memo));
    });
    on<AddMemoranda>((event, emit) async {
      await SQLServices.instance.createMemoranda(Memoranda(
        id: event.id,
        code: event.code,
        memoranda: event.memoranda,
      ));
    });
  }
}
