part of '../wallet.dart'; @freezed sealed class WalletFailure with _$WalletFailure { const WalletFailure._(); /// Gagal di level transport (jaringan, timeout, parsing). const factory WalletFailure.serverError(ApiFailure failure) = _ServerError; const factory WalletFailure.unexpectedError() = _UnexpectedError; const factory WalletFailure.unauthorized() = _Unauthorized; /// `303`, `310`: request tidak lengkap / salah format. const factory WalletFailure.invalidRequest() = _InvalidRequest; /// `304`: ditolak aturan bisnis. [cause] berbahasa Inggris, jangan ditampilkan /// mentah ke customer. const factory WalletFailure.rejected(String cause) = _Rejected; /// `404`. const factory WalletFailure.notFound() = _NotFound; /// `429`: minta OTP terlalu cepat. const factory WalletFailure.tooManyRequests(int retryAfterSeconds) = _TooManyRequests; /// `900`. const factory WalletFailure.internalError() = _InternalError; const factory WalletFailure.pinNotSet() = _PinNotSet; const factory WalletFailure.pinInvalid(int? remainingAttempts) = _PinInvalid; const factory WalletFailure.pinLocked(DateTime? lockedUntil) = _PinLocked; const factory WalletFailure.transferBlocked(DateTime? transferBlockedUntil) = _TransferBlocked; bool get isPinError => maybeMap( pinNotSet: (_) => true, pinInvalid: (_) => true, pinLocked: (_) => true, transferBlocked: (_) => true, orElse: () => false, ); /// Request mungkin tidak sampai / jawaban tidak diterima, sehingga hasilnya /// tidak diketahui. Hanya pada kondisi ini `Idempotency-Key` dipakai ulang. bool get isNetworkError => maybeMap( serverError: (value) => value.failure.maybeMap( connectionError: (_) => true, connectionTimeout: (_) => true, serverError: (e) => e.statusCode == 0, orElse: () => false, ), orElse: () => false, ); }