import 'package:sxchnge_auth/sxchnge_auth.dart'; import '../models/wallet.dart'; import '../transport/backend.dart'; import '../transport/wallet.dart'; abstract final class BackendMapper { static Map request(TransferRequest r) => { 'kind': r.kind.name, 'source': r.source, 'destination': r.destination ?? '', 'amount': r.amount, 'recipient': r.recipient, }; static WalletSnapshot snapshot(BackendDTO d) => WalletSnapshot( accounts: d.accounts.map(WalletMapper.account).toList(), operations: d.operations.map(WalletMapper.operation).toList(), ); static Quote quote(BackendDTO d) => WalletMapper.quote(d.quoteValue); static WalletOperation? operation(BackendDTO d) => d.operationValue == null ? null : WalletMapper.operation(d.operationValue!); static AccountProfile profile(BackendDTO d) => WalletMapper.profile(ProfileDTO(d.locale)); static FactorChallenge challenge( BackendDTO d, FactorPurpose purpose, String operation, ) { final c = d.challenge; return FactorChallenge( id: c.id, purpose: purpose, operation: operation, target: c.target, expiresAt: c.expires, resendAt: c.resend, ); } static WalletError failure(BackendDTO d) => WalletError.values.where((v) => v.name == d.error).firstOrNull ?? WalletError.unavailable; static FactorError factorFailure(BackendDTO d) => switch (d.error) { 'factorInvalid' => FactorError.invalid, 'factorExpired' || 'expiredQuote' => FactorError.expired, 'factorLocked' => FactorError.locked, 'factorCooldown' => FactorError.cooldown, 'factorRequired' => FactorError.required, _ => FactorError.unavailable, }; }