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 LegalBloc {

  ApiProvider _api;

  // Términos y Condiciones
  BehaviorSubject<String> _terminosSubject = new BehaviorSubject();
  Stream<String> get terminosStream => _terminosSubject.stream;

  // Politica de privacidad
  BehaviorSubject<String> _politicaSubject = new BehaviorSubject();
  Stream<String> get politicaStream => _politicaSubject.stream;

  // Aviso legal
  BehaviorSubject<String> _avisoSubject = new BehaviorSubject();
  Stream<String> get avisoStream => _avisoSubject.stream;

  //constructor + singleton
  static LegalBloc _instancia;

  factory LegalBloc({BuildContext context, int company_id}) {
    _instancia = LegalBloc._internal(context, company_id);
    return _instancia;
  }

  LegalBloc._internal(BuildContext context, int company_id) {
    _api = Provider.of<ApiProvider>(context);
    this.getPolitica();
    this.getTerminos();
    this.getAvisoAtleta(company_id);
  }

  get trainingSessionStream => null;

  Future<bool> getPolitica() async {
    var resp = await _api.getPolitica();
    this._politicaSubject.sink.add(resp);
    return true;
  }

  Future<bool> getTerminos() async {
    var resp = await _api.getTerminos();
    this._terminosSubject.sink.add(resp);
    return true;
  }

  Future<bool> getAvisoAtleta(int company_id) async {
    var resp = await _api.getAvisoAtleta(company_id.toString());
    this._avisoSubject.sink.add(resp);
    return true;
  }
}