import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/cupertino.dart';
import '../model/comment_model.dart';
import '../request/comment_request.dart';

part 'comment_event.dart';
part 'comment_state.dart';

class CommentBloc extends Bloc<CommentEvent, CommentState> {
  CommentBloc() : super(const CommentInitial()) {
    on<RequestComment>((event, emit) async {
      await _requestComment(event, emit);
    });
  }

  Future<void> _requestComment(RequestComment event, Emitter<CommentState> emit) async {
    RemoteComment remoteComment = RemoteComment();
    try {
      CommentModel? commentModel = await remoteComment.getCommentModel();
      emit(CommentSuccess(commentModel!));
    } catch (e) {
      emit(const CommentFailed('request false2!'));
    }
  }

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

}

