class UserModel {
  final int userId;
  final String username;
  final String email;
  final String role;
  final String? avatar;
  final int totalScore;
  final int quizzesTaken;

  const UserModel({
    required this.userId,
    required this.username,
    required this.email,
    required this.role,
    this.avatar,
    this.totalScore = 0,
    this.quizzesTaken = 0,
  });

  factory UserModel.fromJson(Map<String, dynamic> json) {
    return UserModel(
      userId: json['user_id'] as int,
      username: json['username'] as String,
      email: json['email'] as String,
      role: (json['role'] as String?) ?? 'user',
      avatar: json['avatar'] as String?,
      totalScore: (json['total_score'] as num?)?.toInt() ?? 0,
      quizzesTaken: (json['quizzes_taken'] as num?)?.toInt() ?? 0,
    );
  }

  UserModel copyWith({int? totalScore, int? quizzesTaken}) {
    return UserModel(
      userId: userId,
      username: username,
      email: email,
      role: role,
      avatar: avatar,
      totalScore: totalScore ?? this.totalScore,
      quizzesTaken: quizzesTaken ?? this.quizzesTaken,
    );
  }
}