

import 'package:app_hit_a_wod/src/models/exercise_benchmark.model.dart';
import 'package:app_hit_a_wod/src/providers/api.provider.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:rxdart/subjects.dart';

class DashboardBloc {

  ApiProvider _api;

  //Benchmarks
  BehaviorSubject<dynamic> _dashboardSubject = new BehaviorSubject();
  Stream<dynamic> get dashboardStream => _dashboardSubject.stream;

  //constructor + singleton
  static DashboardBloc _instancia;

  factory DashboardBloc({BuildContext context, int user_id, int box_id, int subscription_selection_id }) {
    if(_instancia==null) {
      _instancia = DashboardBloc._internal(context, user_id, box_id, subscription_selection_id);
    }
    return _instancia;
  }

  DashboardBloc._internal(BuildContext context, int user_id, int box_id, int subscription_selection_id ) {
    _api = Provider.of<ApiProvider>(context);
    this.refreshInitPage(user_id, box_id, subscription_selection_id);
  }

  Future<bool> refreshInitPage(int user_id, int box_id, int subscription_selection_id) async {
    var resp = await _api.getMobileAppHome(box_id, user_id, subscription_selection_id);
    this._dashboardSubject.sink.add(resp);
    return true;
  }

}