import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/cupertino.dart';
import 'package:ongbut_ntmanh/app/module/school/request/school_request.dart';
import '../model/school_model.dart';


part 'school_event.dart';
part 'school_state.dart';

class SchoolBloc extends Bloc<SchoolEvent, SchoolState> {
  SchoolBloc() : super(const SchoolInitial()) {
    on<RequestSchool>((event, emit) async {
      await _requestSchool(event, emit);
    });
  }

  Future<void> _requestSchool(RequestSchool event, Emitter<SchoolState> emit) async {
    RemoteSchool remoteSchool = RemoteSchool();
    try {
      SchoolModel? schoolModel = await remoteSchool.getSchoolModel();
      emit(SchoolSuccess(schoolModel!));
    } catch (e) {
      emit(const SchoolFailed('request false2!'));
    }
  }

  @override
  Future<void> close() {
    return super.close();
  }

}

