import 'package:pshared/data/mapper/wallet/ui.dart';
import 'package:pshared/models/payment/wallet.dart';
import 'package:pshared/service/wallet.dart' as shared_wallet_service;


abstract class WalletsService {
  Future<List<Wallet>> getWallets(String organizationRef);
  Future<double> getBalance(String organizationRef, String walletRef);
}

class ApiWalletsService implements WalletsService {
  @override
  Future<List<Wallet>> getWallets(String organizationRef) async {
    final models = await shared_wallet_service.WalletService.list(organizationRef);
    return models.map((m) => m.toUi()).toList();
  }

  @override
  Future<double> getBalance(String organizationRef, String walletRef) async {
    final balance = await shared_wallet_service.WalletService.getBalance(
      organizationRef: organizationRef,
      walletRef: walletRef,
    );
    final amount = balance.available?.amount;
    return amount == null ? 0 : double.tryParse(amount) ?? 0;
  }
}
