import 'package:plataforma_educativa/src/bloc/validators.dart';
import 'package:rxdart/rxdart.dart';
import 'dart:async';

class LoginBloc with Validators{
  final _emailController = BehaviorSubject<String>();
  final _passwordController = BehaviorSubject<String>();
  final _groupNameController = BehaviorSubject<String>();

  Stream<String> get emailStream => _emailController.stream.transform(validarEmail);
  Stream<String> get passwordStream => _passwordController.stream.transform(validarPassword);
  Stream<String> get groupNameStream => _groupNameController.stream.transform(validarGroupName);

  Stream<bool> get formValidStream => CombineLatestStream.combine2(passwordStream, passwordStream, (e, p) => true);
  Stream<bool> get nameOkStream => CombineLatestStream.combine2(groupNameStream, groupNameStream, (e, p) => true);

  Function(String) get changeEmail    => _emailController.sink.add;
  Function(String) get changePassword => _passwordController.sink.add;
  Function(String) get changeGroupName => _groupNameController.sink.add;

  String get email    => _emailController.value;
  String get password => _passwordController.value;

  dispose(){
    _emailController.close();
    _passwordController.close();
    _groupNameController.close();
  }
}