import 'package:get/get.dart';
import 'package:sigap/src/features/personalization/presentasion/controllers/settings/base_settings_controller.dart';

class NotificationsController extends BaseSettingsController {
  // Notification settings
  final RxBool messagesNotify = true.obs;
  final RxBool commentsNotify = true.obs;
  final RxBool followersNotify = true.obs;
  final RxBool mentionsNotify = false.obs;
  final RxBool systemNotify = true.obs;

  @override
  void onInit() {
    super.onInit();
    loadSettings();
  }

  // Toggle a notification setting
  void toggleNotification(String type, bool value) {
    switch (type) {
      case 'messages':
        messagesNotify.value = value;
        break;
      case 'comments':
        commentsNotify.value = value;
        break;
      case 'followers':
        followersNotify.value = value;
        break;
      case 'mentions':
        mentionsNotify.value = value;
        break;
      case 'system':
        systemNotify.value = value;
        break;
    }

    saveSettings();
  }

  @override
  Future<bool> saveSettings() async {
    try {
      setLoading(true);

      // TODO: Save notification settings to persistent storage
      final prefs = Get.find<dynamic>(); // Replace with your storage solution
      // await prefs.setBool('notify_messages', messagesNotify.value);
      // await prefs.setBool('notify_comments', commentsNotify.value);
      // await prefs.setBool('notify_followers', followersNotify.value);
      // await prefs.setBool('notify_mentions', mentionsNotify.value);
      // await prefs.setBool('notify_system', systemNotify.value);

      return true;
    } catch (e) {
      setError('Failed to save notification settings: ${e.toString()}');
      return false;
    } finally {
      setLoading(false);
    }
  }

  @override
  Future<void> loadSettings() async {
    try {
      setLoading(true);

      // TODO: Load notification settings from persistent storage
      final prefs = Get.find<dynamic>(); // Replace with your storage solution
      // messagesNotify.value = prefs.getBool('notify_messages') ?? true;
      // commentsNotify.value = prefs.getBool('notify_comments') ?? true;
      // followersNotify.value = prefs.getBool('notify_followers') ?? true;
      // mentionsNotify.value = prefs.getBool('notify_mentions') ?? false;
      // systemNotify.value = prefs.getBool('notify_system') ?? true;
    } catch (e) {
      setError('Failed to load notification settings: ${e.toString()}');
    } finally {
      setLoading(false);
    }
  }
}
