class ProfileUser {
  final String id;
  final String? email;
  final String? phone;
  final String? name;
  final String role;
  final String? createdAt;

  const ProfileUser({
    required this.id,
    this.email,
    this.phone,
    this.name,
    required this.role,
    this.createdAt,
  });

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

  bool get isAdmin => role == 'admin';
  bool get isDriver => role == 'driver';

  String get displayName {
    if (name != null && name!.trim().isNotEmpty) return name!.trim();
    if (email != null && email!.isNotEmpty) return email!;
    return 'Usuario';
  }

  String get initials {
    final source = (name != null && name!.trim().isNotEmpty)
        ? name!.trim()
        : (email ?? '');
    if (source.isEmpty) return 'U';
    return source[0].toUpperCase();
  }
}
