import 'package:pshared/controllers/payment/source.dart';
import 'package:pshared/models/payment/source_type.dart';


typedef SourceOptionKey = ({PaymentSourceType type, String ref});

SourceOptionKey walletOptionKey(String walletRef) =>
    (type: PaymentSourceType.wallet, ref: walletRef);

SourceOptionKey ledgerOptionKey(String ledgerAccountRef) =>
    (type: PaymentSourceType.ledger, ref: ledgerAccountRef);

SourceOptionKey? resolveSelectedSourceOption(PaymentSourceController source) {
  final selectedWallet = source.selectedWallet;
  final selectedLedger = source.selectedLedgerAccount;
  return switch (source.selectedType) {
    PaymentSourceType.wallet =>
      selectedWallet == null ? null : walletOptionKey(selectedWallet.id),
    PaymentSourceType.ledger =>
      selectedLedger == null
          ? null
          : ledgerOptionKey(selectedLedger.ledgerAccountRef),
    null => null,
  };
}
