import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/cupertino.dart';
import '../model/course_model.dart';
import '../request/course_request.dart';
part 'course_event.dart';
part 'course_state.dart';

class CourseBloc extends Bloc<CourseEvent, CourseState> {
  CourseBloc() : super(const CourseInitial()) {
    on<RequestCourse>((event, emit) async {
      await _requestCourse(event, emit);
    });
  }

  Future<void> _requestCourse(RequestCourse event, Emitter<CourseState> emit) async {
    RemoteCourse remoteCourse = RemoteCourse();
    try {
      CourseModel? courseModel = await remoteCourse.getCourseModel();
      emit(CourseSuccess(courseModel!));
    } catch (e) {
      emit(const CourseFailed('request false1!'));
    }
  }

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

}

