/// Model untuk data pengguna yang login.
class UserModel {
  final String id;
  final String name;
  final String email;
  final String? token;
  final String? deviceId;

  const UserModel({
    required this.id,
    required this.name,
    required this.email,
    this.token,
    this.deviceId,
  });

  factory UserModel.fromJson(Map<String, dynamic> json) {
    return UserModel(
      id: json['id'].toString(),
      name: json['name'] as String,
      email: json['email'] as String,
      token: json['token'] as String?,
      deviceId: json['device_id'] as String?,
    );
  }

  Map<String, dynamic> toJson() => {
    'id': id,
    'name': name,
    'email': email,
    if (token != null) 'token': token,
    if (deviceId != null) 'device_id': deviceId,
  };

  UserModel copyWith({
    String? id,
    String? name,
    String? email,
    String? token,
    String? deviceId,
  }) {
    return UserModel(
      id: id ?? this.id,
      name: name ?? this.name,
      email: email ?? this.email,
      token: token ?? this.token,
      deviceId: deviceId ?? this.deviceId,
    );
  }

  @override
  String toString() => 'UserModel(id: $id, name: $name, email: $email, deviceId: $deviceId)';
}
