class AdminUserModel {
  final String id;
  final String? name;
  final String? email;
  final String? phone;
  final String role;

  const AdminUserModel({
    required this.id,
    this.name,
    this.email,
    this.phone,
    this.role = 'citizen',
  });

  String get displayName =>
      (name == null || name!.trim().isEmpty) ? (email ?? phone ?? id) : name!;

  String get initials {
    final source = displayName.trim();
    if (source.isEmpty) return '?';
    final parts = source.split(RegExp(r'\s+'));
    if (parts.length == 1) return parts.first.substring(0, 1).toUpperCase();
    return (parts[0].substring(0, 1) + parts[1].substring(0, 1)).toUpperCase();
  }

  factory AdminUserModel.fromJson(Map<String, dynamic> json) => AdminUserModel(
    id: json['id'].toString(),
    name: json['name'] as String?,
    email: json['email'] as String?,
    phone: json['phone'] as String?,
    role: (json['role'] as String?) ?? 'citizen',
  );
}
