import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../api/api_client_provider.dart';

class SensitivityConfig {
  final bool flipConfirmationEnabled;
  final bool oneWayLatch;
  const SensitivityConfig({
    required this.flipConfirmationEnabled,
    required this.oneWayLatch,
  });

  static const defaults = SensitivityConfig(
    flipConfirmationEnabled: true,
    oneWayLatch: false,
  );
}

/// Fetches the sensitivity config once and caches it for the app lifetime.
/// Falls back to defaults if the request fails.
final sensitivityConfigProvider = FutureProvider<SensitivityConfig>((ref) async {
  try {
    final response = await ref.read(apiClientProvider).get('/api/shared/sensitivity');
    final data = response['data'] as Map<String, dynamic>;
    return SensitivityConfig(
      flipConfirmationEnabled: data['flip_confirmation_enabled'] as bool? ?? true,
      oneWayLatch: data['one_way_latch'] as bool? ?? false,
    );
  } catch (_) {
    return SensitivityConfig.defaults;
  }
});
