import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/sevices/skillshobbies_services.dart';

import '../../model/profile/other_information/skills_and_hobbies.dart';

part 'hoobies_event.dart';
part 'hoobies_state.dart';

class HoobiesBloc extends Bloc<HobbiesEvent, HobbiesState> {
  HoobiesBloc() : super(HoobiesInitial()) {
    List<SkillsHobbies> skillsAndHobbies = [];
    on<GetSkillsHobbies>((event, emit)async {
     emit(HobbiesLoadingState());
     try{
      List<SkillsHobbies> hobbies = await SkillsHobbiesServices.instance.getSkillsHobbies(event.profileId, event.token);
      skillsAndHobbies = hobbies;
      emit(HobbiesLoadedState(skillsAndHobbies: skillsAndHobbies));
     }catch(e){
      emit(HobbiesErrorState(message: e.toString()));
     }
    });
  }
}
