"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.Documents = void 0;
const internal_1 = require("../../../internal");
const conversion_1 = require("../../../utils/conversion");
const internal_2 = require("../../../utils/internal");
/**
 * Handles all Security Token Document related functionality
 */
class Documents extends internal_1.Namespace {
    /**
     * @hidden
     */
    constructor(parent, context) {
        super(parent, context);
        const { ticker } = parent;
        this.set = internal_2.createProcedureMethod({ getProcedureAndArgs: args => [internal_1.setTokenDocuments, Object.assign({ ticker }, args)] }, context);
    }
    /**
     * Retrieve all documents linked to the Security Token
     *
     * @note supports pagination
     */
    get(paginationOpts) {
        return __awaiter(this, void 0, void 0, function* () {
            const { context: { polymeshApi: { query }, }, context, parent: { ticker }, } = this;
            const { entries, lastKey: next } = yield internal_2.requestPaginated(query.asset.assetDocuments, {
                arg: conversion_1.stringToTicker(ticker, context),
                paginationOpts,
            });
            const data = entries.map(([, doc]) => conversion_1.documentToTokenDocument(doc));
            return {
                data,
                next,
            };
        });
    }
}
exports.Documents = Documents;
//# sourceMappingURL=Documents.js.map