import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/sevices/profile/volunatary_services.dart';
import 'package:unit2/sevices/profile/work_history_services.dart';

import '../../model/profile/voluntary_works.dart';

part 'voluntary_work_event.dart';
part 'voluntary_work_state.dart';

class VoluntaryWorkBloc extends Bloc<VoluntaryWorkEvent, VoluntaryWorkState> {
  VoluntaryWorkBloc() : super(VoluntaryWorkInitial()) {
    List<VoluntaryWork> voluntaryWorks = [];
    on<GetVoluntarWorks>((event, emit) async{
      emit(VoluntaryWorkLoadingState());
        try{
          List<VoluntaryWork> works = await VoluntaryService.instance.getVoluntaryWorks(event.profileId, event.token);
            voluntaryWorks = works;
            emit(VoluntaryWorkLoadedState(voluntaryWorks: voluntaryWorks));
        }catch(e){
          emit(VoluntaryWorkErrorState(message: e.toString()));
        }
    });
  }
}
