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

class SupportHandle {
  final String label;
  final String deeplink;
  const SupportHandle({required this.label, required this.deeplink});

  factory SupportHandle.fromJson(Map<String, dynamic> json) =>
      SupportHandle(
        label: json['label'] as String? ?? '',
        deeplink: json['deeplink'] as String? ?? '',
      );
}

class SupportHandles {
  final SupportHandle? wa;
  final SupportHandle? telegram;
  const SupportHandles({this.wa, this.telegram});

  factory SupportHandles.fromJson(Map<String, dynamic> json) {
    SupportHandle? parse(dynamic v) =>
        v is Map<String, dynamic> ? SupportHandle.fromJson(v) : null;
    return SupportHandles(wa: parse(json['wa']), telegram: parse(json['telegram']));
  }
}

final supportHandlesProvider = FutureProvider<SupportHandles>((ref) async {
  final api = ref.read(apiClientProvider);
  final response = await api.get('/api/shared/support-handles');
  final data = response['data'] as Map<String, dynamic>? ?? const {};
  return SupportHandles.fromJson(data);
});
