import 'dart:async';
import 'dart:convert';

import 'package:flutter/material.dart';
import '../product/base/bloc/base_bloc.dart';
import '../product/services/api_services.dart';
import '../feature/bell/bell_model.dart';
import '../feature/settings/profile/profile_model.dart';

class MainBloc extends BlocBase {
  APIServices apiServices = APIServices();
  final bellBloc = StreamController<Bell>.broadcast();
  StreamSink<Bell> get sinkBellBloc => bellBloc.sink;
  Stream<Bell> get streamBellBloc => bellBloc.stream;

  final language = StreamController<Locale?>.broadcast();
  StreamSink<Locale?> get sinkLanguage => language.sink;
  Stream<Locale?> get streamLanguage => language.stream;

  final theme = StreamController<ThemeData?>.broadcast();
  StreamSink<ThemeData?> get sinkTheme => theme.sink;
  Stream<ThemeData?> get streamTheme => theme.stream;

  final themeMode = StreamController<bool>.broadcast();
  StreamSink<bool> get sinkThemeMode => themeMode.sink;
  Stream<bool> get streamThemeMode => themeMode.stream;

  final isVNIcon = StreamController<bool>.broadcast();
  StreamSink<bool> get sinkIsVNIcon => isVNIcon.sink;
  Stream<bool> get streamIsVNIcon => isVNIcon.stream;

  final userProfile = StreamController<User>.broadcast();
  StreamSink<User> get sinkUserProfile => userProfile.sink;
  Stream<User> get streamUserProfile => userProfile.stream;

  @override
  void dispose() {}

  void getUserProfile() async {
    String data = await apiServices.getUserDetail();
    User user = User.fromJson(jsonDecode(data));
    sinkUserProfile.add(user);
  }
}
