Files
sendico/frontend/pshared/lib/models/payment/source.dart
2026-02-04 02:01:22 +03:00

32 lines
913 B
Dart

import 'package:pshared/models/ledger/account.dart';
import 'package:pshared/models/payment/wallet.dart';
enum PaymentSourceType { wallet, ledger }
class PaymentSource {
final PaymentSourceType type;
final Wallet? wallet;
final LedgerAccount? ledgerAccount;
const PaymentSource._({required this.type, this.wallet, this.ledgerAccount});
const PaymentSource.wallet(Wallet wallet)
: this._(type: PaymentSourceType.wallet, wallet: wallet);
const PaymentSource.ledger(LedgerAccount account)
: this._(type: PaymentSourceType.ledger, ledgerAccount: account);
String get id => switch (type) {
PaymentSourceType.wallet => wallet!.id,
PaymentSourceType.ledger => ledgerAccount!.ledgerAccountRef,
};
String get key => '${type.name}:$id';
String get name => switch (type) {
PaymentSourceType.wallet => wallet!.name,
PaymentSourceType.ledger => ledgerAccount!.name,
};
}