"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetAllWalletBalancesUseCase = void 0;
const not_found_error_1 = require("../../../domain/errors/not-found-error");
const TOKEN_PAGE_LIMIT = 1000;
class GetAllWalletBalancesUseCase {
    walletRepository;
    addressRepository;
    tokenRepository;
    transactionRepository;
    balanceService;
    constructor(walletRepository, addressRepository, tokenRepository, transactionRepository, balanceService) {
        this.walletRepository = walletRepository;
        this.addressRepository = addressRepository;
        this.tokenRepository = tokenRepository;
        this.transactionRepository = transactionRepository;
        this.balanceService = balanceService;
    }
    async execute(walletId) {
        const wallet = await this.walletRepository.findById(walletId);
        if (!wallet) {
            throw new not_found_error_1.NotFoundError('Wallet', walletId);
        }
        const addresses = await this.addressRepository.findByWalletId(walletId);
        const addressIds = addresses.map((address) => address.id);
        if (addressIds.length === 0) {
            return [];
        }
        const transactions = await this.transactionRepository.findByAddressIds(addressIds);
        const tokens = await this.tokenRepository.findAll({ limit: TOKEN_PAGE_LIMIT });
        return this.balanceService.calculate(addresses, transactions, tokens);
    }
}
exports.GetAllWalletBalancesUseCase = GetAllWalletBalancesUseCase;
//# sourceMappingURL=get-all-wallet-balances.use-case.js.map