

import 'package:app_hit_a_wod/src/models/array_response.model.dart';
import 'package:app_hit_a_wod/src/models/box_order.model.dart';
import 'package:app_hit_a_wod/src/providers/api.provider.dart';
import 'package:rxdart/subjects.dart';

class MyOrdersBloc {

  ApiProvider _api;

  int _user_id;
  int _box_id;

  BehaviorSubject<List<BoxOrder>> _ordersSubject = new BehaviorSubject();
  Stream<List<BoxOrder>> get ordersStream => _ordersSubject.stream;

  MyOrdersBloc(int this._user_id, int this._box_id, ApiProvider this._api) {
    this._fetchOrders();
  }

  _fetchOrders() async {
    ArrayResponse<BoxOrder> data = await _api.getBoxUserOrders(_box_id, _user_id);
    _ordersSubject.sink.add(data.data as List<BoxOrder>);
  }

}