import 'package:flutter/material.dart';
import 'package:prosapp_web_app/models/setting.dart';
import 'package:prosapp_web_app/services/api_service.dart';

class SettingsProvider extends ChangeNotifier {
  Setting? settings;
  bool isLoading = true;
  final _api = ApiService.instance;

  SettingsProvider() {
    getSettings();
  }

  getSettings() async {
    try {
      final data = await _api.get('/settings').timeout(const Duration(seconds: 10));
      if (data != null) {
        settings = Setting.fromDocument(data as Map<String, dynamic>);
      }
    } catch (e) {
      print('Error obteniendo los settings: $e');
    } finally {
      settings ??= Setting.fromDocument({});
      isLoading = false;
      notifyListeners();
    }
  }
}
