authentication_state.model.dart 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import 'dart:convert';
  2. import 'package:immich_mobile/shared/models/device_info.model.dart';
  3. class AuthenticationState {
  4. final String deviceId;
  5. final String deviceType;
  6. final String userId;
  7. final String userEmail;
  8. final bool isAuthenticated;
  9. final String firstName;
  10. final String lastName;
  11. final bool isAdmin;
  12. final bool isFirstLogin;
  13. final String profileImagePath;
  14. final DeviceInfoRemote deviceInfo;
  15. AuthenticationState({
  16. required this.deviceId,
  17. required this.deviceType,
  18. required this.userId,
  19. required this.userEmail,
  20. required this.isAuthenticated,
  21. required this.firstName,
  22. required this.lastName,
  23. required this.isAdmin,
  24. required this.isFirstLogin,
  25. required this.profileImagePath,
  26. required this.deviceInfo,
  27. });
  28. AuthenticationState copyWith({
  29. String? deviceId,
  30. String? deviceType,
  31. String? userId,
  32. String? userEmail,
  33. bool? isAuthenticated,
  34. String? firstName,
  35. String? lastName,
  36. bool? isAdmin,
  37. bool? isFirstLoggedIn,
  38. String? profileImagePath,
  39. DeviceInfoRemote? deviceInfo,
  40. }) {
  41. return AuthenticationState(
  42. deviceId: deviceId ?? this.deviceId,
  43. deviceType: deviceType ?? this.deviceType,
  44. userId: userId ?? this.userId,
  45. userEmail: userEmail ?? this.userEmail,
  46. isAuthenticated: isAuthenticated ?? this.isAuthenticated,
  47. firstName: firstName ?? this.firstName,
  48. lastName: lastName ?? this.lastName,
  49. isAdmin: isAdmin ?? this.isAdmin,
  50. isFirstLogin: isFirstLoggedIn ?? isFirstLogin,
  51. profileImagePath: profileImagePath ?? this.profileImagePath,
  52. deviceInfo: deviceInfo ?? this.deviceInfo,
  53. );
  54. }
  55. @override
  56. String toString() {
  57. return 'AuthenticationState(deviceId: $deviceId, deviceType: $deviceType, userId: $userId, userEmail: $userEmail, isAuthenticated: $isAuthenticated, firstName: $firstName, lastName: $lastName, isAdmin: $isAdmin, isFirstLoggedIn: $isFirstLogin, profileImagePath: $profileImagePath, deviceInfo: $deviceInfo)';
  58. }
  59. Map<String, dynamic> toMap() {
  60. final result = <String, dynamic>{};
  61. result.addAll({'deviceId': deviceId});
  62. result.addAll({'deviceType': deviceType});
  63. result.addAll({'userId': userId});
  64. result.addAll({'userEmail': userEmail});
  65. result.addAll({'isAuthenticated': isAuthenticated});
  66. result.addAll({'firstName': firstName});
  67. result.addAll({'lastName': lastName});
  68. result.addAll({'isAdmin': isAdmin});
  69. result.addAll({'isFirstLogin': isFirstLogin});
  70. result.addAll({'profileImagePath': profileImagePath});
  71. result.addAll({'deviceInfo': deviceInfo.toMap()});
  72. return result;
  73. }
  74. factory AuthenticationState.fromMap(Map<String, dynamic> map) {
  75. return AuthenticationState(
  76. deviceId: map['deviceId'] ?? '',
  77. deviceType: map['deviceType'] ?? '',
  78. userId: map['userId'] ?? '',
  79. userEmail: map['userEmail'] ?? '',
  80. isAuthenticated: map['isAuthenticated'] ?? false,
  81. firstName: map['firstName'] ?? '',
  82. lastName: map['lastName'] ?? '',
  83. isAdmin: map['isAdmin'] ?? false,
  84. isFirstLogin: map['isFirstLogin'] ?? false,
  85. profileImagePath: map['profileImagePath'] ?? '',
  86. deviceInfo: DeviceInfoRemote.fromMap(map['deviceInfo']),
  87. );
  88. }
  89. String toJson() => json.encode(toMap());
  90. factory AuthenticationState.fromJson(String source) => AuthenticationState.fromMap(json.decode(source));
  91. @override
  92. bool operator ==(Object other) {
  93. if (identical(this, other)) return true;
  94. return other is AuthenticationState &&
  95. other.deviceId == deviceId &&
  96. other.deviceType == deviceType &&
  97. other.userId == userId &&
  98. other.userEmail == userEmail &&
  99. other.isAuthenticated == isAuthenticated &&
  100. other.firstName == firstName &&
  101. other.lastName == lastName &&
  102. other.isAdmin == isAdmin &&
  103. other.isFirstLogin == isFirstLogin &&
  104. other.profileImagePath == profileImagePath &&
  105. other.deviceInfo == deviceInfo;
  106. }
  107. @override
  108. int get hashCode {
  109. return deviceId.hashCode ^
  110. deviceType.hashCode ^
  111. userId.hashCode ^
  112. userEmail.hashCode ^
  113. isAuthenticated.hashCode ^
  114. firstName.hashCode ^
  115. lastName.hashCode ^
  116. isAdmin.hashCode ^
  117. isFirstLogin.hashCode ^
  118. profileImagePath.hashCode ^
  119. deviceInfo.hashCode;
  120. }
  121. }