temp build
This commit is contained in:
@@ -1,86 +1,97 @@
|
||||
import 'package:pshared/models/payment/methods/card.dart';
|
||||
import 'package:pshared/models/payment/methods/iban.dart';
|
||||
import 'package:pshared/models/payment/methods/crypto_address.dart';
|
||||
import 'package:pshared/models/payment/methods/russian_bank.dart';
|
||||
import 'package:pshared/models/payment/methods/wallet.dart';
|
||||
import 'package:pshared/models/describable.dart';
|
||||
import 'package:pshared/models/organization/bound.dart';
|
||||
import 'package:pshared/models/permissions/bound/describable.dart';
|
||||
import 'package:pshared/models/permissions/bound.dart';
|
||||
import 'package:pshared/models/recipient/status.dart';
|
||||
import 'package:pshared/models/recipient/type.dart';
|
||||
import 'package:pshared/models/storable.dart';
|
||||
|
||||
|
||||
class Recipient {
|
||||
final String? avatarUrl; // network URL / local asset
|
||||
final String name;
|
||||
class Recipient implements PermissionBoundStorableDescribable {
|
||||
final Storable storable;
|
||||
final PermissionBound permissionBound;
|
||||
final Describable describable;
|
||||
final String email;
|
||||
final String? avatarUrl;
|
||||
final RecipientStatus status;
|
||||
final RecipientType type;
|
||||
final CardPaymentMethod? card;
|
||||
final IbanPaymentMethod? iban;
|
||||
final RussianBankAccountPaymentMethod? bank;
|
||||
final WalletPaymentMethod? wallet;
|
||||
final CryptoAddressPaymentMethod? cryptoAddress;
|
||||
final bool isArchived;
|
||||
|
||||
const Recipient({
|
||||
this.avatarUrl,
|
||||
required this.name,
|
||||
required this.storable,
|
||||
required this.permissionBound,
|
||||
required this.describable,
|
||||
required this.email,
|
||||
required this.status,
|
||||
required this.type,
|
||||
this.card,
|
||||
this.iban,
|
||||
this.bank,
|
||||
this.wallet,
|
||||
this.cryptoAddress,
|
||||
this.avatarUrl,
|
||||
this.isArchived = false,
|
||||
});
|
||||
|
||||
/// Convenience factory for quickly creating mock recipients.
|
||||
factory Recipient.mock({
|
||||
required String name,
|
||||
required String email,
|
||||
required RecipientStatus status,
|
||||
required RecipientType type,
|
||||
CardPaymentMethod? card,
|
||||
IbanPaymentMethod? iban,
|
||||
RussianBankAccountPaymentMethod? bank,
|
||||
WalletPaymentMethod? wallet,
|
||||
CryptoAddressPaymentMethod? cryptoAddress,
|
||||
}) =>
|
||||
Recipient(
|
||||
avatarUrl: null,
|
||||
name: name,
|
||||
email: email,
|
||||
status: status,
|
||||
type: type,
|
||||
card: card,
|
||||
iban: iban,
|
||||
bank: bank,
|
||||
wallet: wallet,
|
||||
cryptoAddress: cryptoAddress,
|
||||
);
|
||||
@override
|
||||
String get id => storable.id;
|
||||
@override
|
||||
DateTime get createdAt => storable.createdAt;
|
||||
@override
|
||||
DateTime get updatedAt => storable.updatedAt;
|
||||
|
||||
@override
|
||||
String get organizationRef => permissionBound.organizationRef;
|
||||
@override
|
||||
String get permissionRef => permissionBound.permissionRef;
|
||||
|
||||
@override
|
||||
String get name => describable.name;
|
||||
@override
|
||||
String? get description => describable.description;
|
||||
|
||||
Recipient copyWith({
|
||||
Describable? describable,
|
||||
String? email,
|
||||
String? Function()? avatarUrl,
|
||||
RecipientStatus? status,
|
||||
RecipientType? type,
|
||||
bool? isArchived,
|
||||
}) => Recipient(
|
||||
storable: storable,
|
||||
permissionBound: permissionBound,
|
||||
describable: describableCopyWithOther(this.describable, describable),
|
||||
email: email ?? this.email,
|
||||
avatarUrl: avatarUrl != null ? avatarUrl() : this.avatarUrl,
|
||||
status: status ?? this.status,
|
||||
type: type ?? this.type,
|
||||
isArchived: isArchived ?? this.isArchived,
|
||||
);
|
||||
|
||||
// TODO: move search to backend
|
||||
bool matchesQuery(String q) {
|
||||
final searchable = [
|
||||
name,
|
||||
email,
|
||||
card?.pan,
|
||||
card?.firstName,
|
||||
card?.lastName,
|
||||
iban?.iban,
|
||||
iban?.accountHolder,
|
||||
iban?.bic,
|
||||
iban?.bankName,
|
||||
bank?.accountNumber,
|
||||
bank?.recipientName,
|
||||
bank?.inn,
|
||||
bank?.kpp,
|
||||
bank?.bankName,
|
||||
bank?.bik,
|
||||
bank?.correspondentAccount,
|
||||
wallet?.walletId,
|
||||
cryptoAddress?.address,
|
||||
cryptoAddress?.network,
|
||||
cryptoAddress?.destinationTag,
|
||||
];
|
||||
|
||||
return searchable.any((field) => field?.toLowerCase().contains(q) ?? false);
|
||||
return searchable.any((field) => field.toLowerCase().contains(q.toLowerCase()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Recipient newRecipient({
|
||||
required String organizationRef,
|
||||
required String email,
|
||||
required String name,
|
||||
required RecipientStatus status,
|
||||
required RecipientType type,
|
||||
String? description,
|
||||
String? avatarUrl,
|
||||
bool isArchived = false,
|
||||
}) =>
|
||||
Recipient(
|
||||
storable: newStorable(),
|
||||
permissionBound: newPermissionBound(organizationBound: newOrganizationBound(organizationRef: organizationRef)),
|
||||
describable: newDescribable(name: name, description: description),
|
||||
email: email,
|
||||
status: status,
|
||||
type: type,
|
||||
avatarUrl: avatarUrl,
|
||||
isArchived: isArchived,
|
||||
);
|
||||
Reference in New Issue
Block a user