import 'package:drift/drift.dart' hide Index; import 'package:immich_mobile/domain/models/user.model.dart'; import 'package:immich_mobile/domain/models/user_metadata.model.dart'; import 'package:immich_mobile/infrastructure/entities/user.entity.drift.dart'; import 'package:immich_mobile/infrastructure/utils/drift_default.mixin.dart'; import 'package:immich_mobile/utils/hash.dart'; import 'package:isar/isar.dart'; part 'user.entity.g.dart'; // TODO: Remove User once Isar is removed @Collection(inheritance: false) class IsarUser { Id get isarId => fastHash(id); @Index(unique: true, replace: false, type: IndexType.hash) final String id; final DateTime updatedAt; final String email; final String name; final bool isPartnerSharedBy; final bool isPartnerSharedWith; final bool isAdmin; final String profileImagePath; @Enumerated(EnumType.ordinal) final AvatarColor avatarColor; final bool memoryEnabled; final bool inTimeline; final int quotaUsageInBytes; final int quotaSizeInBytes; const IsarUser({ required this.id, required this.updatedAt, required this.email, required this.name, required this.isAdmin, this.isPartnerSharedBy = false, this.isPartnerSharedWith = false, this.profileImagePath = '', this.avatarColor = AvatarColor.primary, this.memoryEnabled = true, this.inTimeline = false, this.quotaUsageInBytes = 0, this.quotaSizeInBytes = 0, }); static IsarUser fromDto(UserDto dto) => IsarUser( id: dto.id, updatedAt: dto.updatedAt, email: dto.email, name: dto.name, isAdmin: dto.isAdmin, isPartnerSharedBy: dto.isPartnerSharedBy, isPartnerSharedWith: dto.isPartnerSharedWith, profileImagePath: dto.profileImagePath ?? "", avatarColor: dto.avatarColor, memoryEnabled: dto.memoryEnabled, inTimeline: dto.inTimeline, quotaUsageInBytes: dto.quotaUsageInBytes, quotaSizeInBytes: dto.quotaSizeInBytes, ); UserDto toDto() => UserDto( id: id, email: email, name: name, isAdmin: isAdmin, updatedAt: updatedAt, profileImagePath: profileImagePath.isEmpty ? null : profileImagePath, avatarColor: avatarColor, memoryEnabled: memoryEnabled, inTimeline: inTimeline, isPartnerSharedBy: isPartnerSharedBy, isPartnerSharedWith: isPartnerSharedWith, quotaUsageInBytes: quotaUsageInBytes, quotaSizeInBytes: quotaSizeInBytes, ); } class UserEntity extends Table with DriftDefaultsMixin { const UserEntity(); TextColumn get id => text()(); TextColumn get name => text()(); TextColumn get email => text()(); DateTimeColumn get deletedAt => dateTime().nullable()(); IntColumn get avatarColor => intEnum().nullable()(); @override Set get primaryKey => {id}; } extension UserEntityDataDomainEx on UserEntityData { User toDto() => User( id: id, name: name, email: email, deletedAt: deletedAt, avatarColor: avatarColor, ); }