import 'package:farm_tpf/data/repository/user_repository.dart';
import 'package:rxdart/rxdart.dart';

class GetAccountBloc {
  final _repository = UserRepository();
  final _getAccountFetcher = PublishSubject<dynamic>();

  Stream<dynamic> get actions => _getAccountFetcher.stream;

  void getAccount(Function(dynamic) onSuccess, Function(String) onError) async {
    _repository.getUser().then((value) {
      onSuccess(value);
      _getAccountFetcher.sink.add(value);
    }).catchError((onError) {
      onError(onError);
      _getAccountFetcher.addError(onError);
    });
  }

  void dispose() async {
    await _getAccountFetcher.drain();
    _getAccountFetcher.close();
  }
}

final getAccountBloc = GetAccountBloc();
