// 与 Web `stores/transfer.ts` 对齐的账户类型与划转组合规则。
const kWalletSpot = 'SPOT';
const kWalletSwap = 'SWAP';
const kWalletFollow = 'FOLLOW';
const kWalletSpotTrading = 'SPOT_TRADING';

const kOtherWalletTypes = <String>[
  kWalletSwap,
  kWalletFollow,
  kWalletSpotTrading,
];

const kSwapAccountIdx = 0;
const kFollowAccountIdx = 1;
const kSpotAccountIdx = 2;

/// 有效组合：仅「资金↔合约/跟单」或「资金↔现货交易账户」，其余回退 SPOT↔SWAP。
(String, String) normalizeTransferPair(String a, String b) {
  if (a == b) {
    return (kWalletSpot, kWalletSwap);
  }
  final isSpotTradingBridge =
      (a == kWalletSpot && b == kWalletSpotTrading) ||
      (a == kWalletSpotTrading && b == kWalletSpot);
  if (isSpotTradingBridge) {
    return (a, b);
  }
  final isFundingBridge = (a == kWalletSpot &&
          (b == kWalletSwap || b == kWalletFollow)) ||
      (b == kWalletSpot && (a == kWalletSwap || a == kWalletFollow));
  if (isFundingBridge) {
    return (a, b);
  }
  return (kWalletSpot, kWalletSwap);
}

bool involvesSpotTradingBridge(String from, String to) {
  return (from == kWalletSpot && to == kWalletSpotTrading) ||
      (from == kWalletSpotTrading && to == kWalletSpot);
}

int walletTypeToAccountIndex(String walletType) {
  switch (walletType) {
    case kWalletSwap:
      return kSwapAccountIdx;
    case kWalletFollow:
      return kFollowAccountIdx;
    case kWalletSpot:
      return kSpotAccountIdx;
    default:
      return -1;
  }
}
