"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AssetHolders = void 0;
const internal_1 = require("../../../internal");
const conversion_1 = require("../../../utils/conversion");
const internal_2 = require("../../../utils/internal");
/**
 * Handles all Asset Holders related functionality
 */
class AssetHolders extends internal_1.Namespace {
    /**
     * Retrieve all the Asset Holders with their respective balance
     *
     * @note supports pagination
     */
    get(paginationOpts) {
        return __awaiter(this, void 0, void 0, function* () {
            const { context: { polymeshApi: { query }, }, context, parent: { ticker }, } = this;
            const rawTicker = conversion_1.stringToTicker(ticker, context);
            const { entries, lastKey: next } = yield internal_2.requestPaginated(query.asset.balanceOf, {
                arg: rawTicker,
                paginationOpts,
            });
            const data = entries.map(([storageKey, balance]) => ({
                identity: new internal_1.Identity({ did: conversion_1.identityIdToString(storageKey.args[1]) }, context),
                balance: conversion_1.balanceToBigNumber(balance),
            }));
            return {
                data,
                next,
            };
        });
    }
}
exports.AssetHolders = AssetHolders;
//# sourceMappingURL=AssetHolders.js.map