import 'package:equatable/equatable.dart'; import 'package:user_repository/user_repository.dart'; class MyUser extends Equatable { final String id; final String? email; final String? phone; final String? name; final String? nickname; final String? city; final String? picture; final String? birthday; final String? gender; final ProState proState; final String? token; final bool isPhoneVerified; final DateTime? rejectedAt; const MyUser({ required this.id, this.email, this.phone, this.name, this.nickname, this.city, this.picture, this.birthday, this.gender, required this.proState, this.token, this.isPhoneVerified = false, this.rejectedAt, }); get drawerLabel => email != null && email!.isNotEmpty ? email! : phone != null && phone!.isNotEmpty ? phone! : "N/A"; /// Empty user which represents an unauthenticated user. static const empty = MyUser( id: '', email: '', phone: '', name: '', nickname: '', city: '', picture: '', birthday: '', gender: '', proState: ProState.inactive, token: '', isPhoneVerified: false, ); /// Modify MyUser parameters MyUser copyWith({ String? id, String? email, String? phone, String? name, String? nickname, String? city, String? picture, String? birthday, String? gender, ProState? proState, String? token, bool? isPhoneVerified, DateTime? rejectedAt, }) { return MyUser( id: id ?? this.id, email: email ?? this.email, phone: phone ?? this.phone, name: name ?? this.name, nickname: nickname ?? this.nickname, city: city ?? this.city, picture: picture ?? this.picture, birthday: birthday ?? this.birthday, gender: gender ?? this.gender, proState: proState ?? this.proState, token: token ?? this.token, isPhoneVerified: isPhoneVerified ?? this.isPhoneVerified, rejectedAt: rejectedAt ?? this.rejectedAt, ); } /// Convenience getter to determine whether the current user is empty. bool get isEmpty => this == MyUser.empty; /// Convenience getter to determine whether the current user is not empty. bool get isNotEmpty => this != MyUser.empty; MyUserEntity toEntity() { return MyUserEntity( id: id, email: email, phone: phone, name: name, nickname: nickname, city: city, picture: picture, birthday: birthday, gender: gender, proState: proState, token: token, ); } static MyUser fromEntity(MyUserEntity entity) { return MyUser( id: entity.id, email: entity.email, phone: entity.phone, name: entity.name, nickname: entity.nickname, city: entity.city, picture: entity.picture, birthday: entity.birthday, gender: entity.gender, proState: entity.proState, token: entity.token, ); } @override List get props => [ id, email, phone, name, nickname, city, picture, birthday, gender, proState, token, isPhoneVerified, rejectedAt, ]; }