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

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

part 'organization_membership_event.dart';
part 'organization_membership_state.dart';

class OrganizationMembershipBloc extends Bloc<OrganizationMembershipEvent, OrganizationMembershipState> {
  OrganizationMembershipBloc() : super(OrganizationMembershipInitial()) {
    List<OrganizationMembership> organizationMemberships=[];
    on<GetOrganizationMembership>((event, emit) async{
     emit(OrgmembershipLoadingState());
     try{
       List<OrganizationMembership> orgs = await OrganizationMembershipServices.instance.getOrgMemberships(event.profileId, event.token);
      organizationMemberships = orgs;
      emit(OrganizationMembershipLoaded(orgMemberships: organizationMemberships));
     }catch(e){
      OrganizationMembershipErrorState(message: e.toString());
     }
    });
  }
}
