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

import '../../../../../model/passo/signatories.dart';
import '../../../../../sevices/offline/offline_passo/admin/sql_services/sql_services.dart';

part 'signatories_admin_event.dart';
part 'signatories_admin_state.dart';

class SignatoriesAdminBloc
    extends Bloc<SignatoriesAdminEvent, SignatoriesAdminState> {
  SignatoriesAdminBloc() : super(SignatoriesAdminInitial()) {
    List<Signatories> signatories = [];
    on<LoadSignatories>((event, emit) async {
      signatories = await SQLServices.instance.readAllSignatories();

      emit(SignatoriesLoaded(signatories: signatories));
    });
    on<AddSignatories>((event, emit) async {
      await SQLServices.instance.createSignatories(Signatories(
        id: event.id,
        signatoryId: event.signatoryId,
        firstname: event.firstname,
        middlename: event.middlename,
        lastname: event.lastname,
        designation: event.designation,
        // status: event.status
        // genCode: event.genCode
      ));
    });
  }
}
