/// Model for a user as returned by the admin endpoint.
class UserAdmin {
  final int id;
  final String username;
  final String email;
  final String? firstName;
  final String? lastName;
  final String role;
  final bool isPremium;
  final bool canShareRecipes;
  final DateTime? createdAt;

  const UserAdmin({
    required this.id,
    required this.username,
    required this.email,
    this.firstName,
    this.lastName,
    required this.role,
    required this.isPremium,
    required this.canShareRecipes,
    this.createdAt,
  });

  factory UserAdmin.fromJson(Map<String, dynamic> json) => UserAdmin(
        id: json['id'] as int,
        username: json['username'] as String,
        email: json['email'] as String? ?? '',
        firstName: json['firstName'] as String?,
        lastName: json['lastName'] as String?,
        role: json['role'] as String? ?? 'user',
        isPremium: json['isPremium'] as bool? ?? false,
        canShareRecipes: json['canShareRecipes'] as bool? ?? true,
        createdAt: json['createdAt'] != null ? DateTime.tryParse(json['createdAt'] as String) : null,
      );

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

  String get displayName {
    final parts = [firstName, lastName].where((s) => s != null && s.isNotEmpty).toList();
    return parts.isNotEmpty ? parts.join(' ') : username;
  }
}
