import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/model/profile/profileInfomation.dart';
import 'package:unit2/sevices/profile/profile_service.dart';
part 'profile_event.dart';
part 'profile_state.dart';

class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
  ProfileBloc() : super(ProfileInitial()) {
    ProfileInformation? globalProfileInformation;
    on<LoadProfile>((event, emit) async {
              emit(ProfileLoading());
      try {

        ProfileInformation? profileInformation =
            await ProfileService.instance.getProfile(event.token, event.userID);
        globalProfileInformation = profileInformation;
        emit(ProfileLoaded(profileInformation: globalProfileInformation!));
      } catch (e) {
        emit(ProfileErrorState(mesage: e.toString()));
      }
    });

   
  }
}
