class UserModel { final String id; final String uniqueId; final String name; final String email; final String phone; final String role; final String sbu; final String createdAt; final String updatedAt; final String? fcmToken; final Avatar? avatar; UserModel({ required this.id, required this.uniqueId, required this.name, required this.email, required this.phone, required this.role, required this.sbu, required this.createdAt, required this.updatedAt, this.fcmToken, this.avatar, }); // Factory constructor for converting JSON to UserModel factory UserModel.fromJson(Map json) { return UserModel( id: json['_id'], uniqueId: json['uniqueId'], name: json['name'], email: json['email'], phone: json['phone'], role: json['role'], sbu: json['SBU'], createdAt: json['createdAt'], updatedAt: json['updatedAt'], fcmToken: json['fcm_token'], avatar: json['avatar'] != null ? Avatar.fromJson(json['avatar']) : null, ); } // Method to convert UserModel to JSON Map toJson() { return { '_id': id, 'uniqueId': uniqueId, 'name': name, 'email': email, 'phone': phone, 'role': role, 'SBU': sbu, 'createdAt': createdAt, 'updatedAt': updatedAt, 'fcm_token': fcmToken, 'avatar': avatar?.toJson(), }; } // Overriding toString to get a readable output for debugging @override String toString() { return 'UserModel{id: $id, uniqueId: $uniqueId, name: $name, email: $email, phone: $phone, role: $role, sbu: $sbu, createdAt: $createdAt, updatedAt: $updatedAt, fcmToken: $fcmToken, avatar: $avatar}'; } } // Avatar model to handle avatar data class Avatar { final String publicId; final String url; Avatar({ required this.publicId, required this.url, }); // Factory constructor for converting JSON to Avatar factory Avatar.fromJson(Map json) { return Avatar( publicId: json['public_id'] ?? '', url: json['url'] ?? '', ); } // Method to convert Avatar to JSON Map toJson() { return { 'public_id': publicId, 'url': url, }; } @override String toString() { return 'Avatar{publicId: $publicId, url: $url}'; } }