import 'package:didvan/models/enums.dart';
import 'package:didvan/providers/core_provider.dart';
import 'package:didvan/services/storage/storage.dart';

class GeneralSettingsState extends CoreProvier {
  GeneralSettingsState() {
    getSettingsFromStorage();
  }

  List _notificationTimeRange = ['00:00', '23:59'];
  String _fontFamily = 'Dana-FA';
  double _fontSizeScale = 1;
  String _brightness = 'light';

  set notificationTimeRange(List value) {
    _notificationTimeRange = value;
    StorageService.setValue(
      key: 'notificationTimeRangeStart',
      value: value[0],
    );
    StorageService.setValue(
      key: 'notificationTimeRangeStart',
      value: value[1],
    );
  }

  List get notificationTimeRange => _notificationTimeRange;

  set fontFamily(String value) {
    _fontFamily = value;
    StorageService.setValue(
      key: 'fontFamily',
      value: value,
    );
    notifyListeners();
  }

  String get fontFamily => _fontFamily;

  set fontSizeScale(double value) {
    _fontSizeScale = value;
    StorageService.setValue(
      key: 'fontSizeScale',
      value: value,
    );
    notifyListeners();
  }

  double get fontSizeScale => _fontSizeScale;

  set brightness(String value) {
    _brightness = value;
    StorageService.setValue(
      key: 'brightness',
      value: value,
    );
    notifyListeners();
  }

  String get brightness => _brightness;

  Future<void> getSettingsFromStorage() async {
    appState = AppState.busy;
    _notificationTimeRange[0] =
        await StorageService.getValue(key: 'notificationTimeRangeStart');
    _notificationTimeRange[1] =
        await StorageService.getValue(key: 'notificationTimeRangeEnd');
    _fontFamily = await StorageService.getValue(key: 'fontFamily');
    _brightness = await StorageService.getValue(key: 'brightness');
    final scale = await StorageService.getValue(key: 'fontSizeScale');
    _fontSizeScale = double.parse(scale);
    appState = AppState.idle;
  }
}
