"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.TrustedClaimIssuers = void 0;
const internal_1 = require("../../../../internal");
const internal_2 = require("../../../../types/internal");
const conversion_1 = require("../../../../utils/conversion");
const internal_3 = require("../../../../utils/internal");
/**
 * Handles all Asset Default Trusted Claim Issuers related functionality
 */
class TrustedClaimIssuers extends internal_1.Namespace {
    /**
     * @hidden
     */
    constructor(parent, context) {
        super(parent, context);
        const { ticker } = parent;
        this.set = (0, internal_3.createProcedureMethod)({
            getProcedureAndArgs: args => [
                internal_1.modifyAssetTrustedClaimIssuers,
                Object.assign(Object.assign({ ticker }, args), { operation: internal_2.TrustedClaimIssuerOperation.Set }),
            ],
        }, context);
        this.add = (0, internal_3.createProcedureMethod)({
            getProcedureAndArgs: args => [
                internal_1.modifyAssetTrustedClaimIssuers,
                Object.assign(Object.assign({ ticker }, args), { operation: internal_2.TrustedClaimIssuerOperation.Add }),
            ],
        }, context);
        this.remove = (0, internal_3.createProcedureMethod)({
            getProcedureAndArgs: args => [
                internal_1.modifyAssetTrustedClaimIssuers,
                Object.assign(Object.assign({ ticker }, args), { operation: internal_2.TrustedClaimIssuerOperation.Remove }),
            ],
        }, context);
    }
    // eslint-disable-next-line require-jsdoc
    get(callback) {
        return __awaiter(this, void 0, void 0, function* () {
            const { context: { polymeshApi: { query: { complianceManager }, }, }, context, parent: { ticker }, } = this;
            const rawTicker = (0, conversion_1.stringToTicker)(ticker, context);
            const assembleResult = (issuers) => issuers.map(issuer => {
                const { identity: { did }, trustedFor, } = (0, conversion_1.trustedIssuerToTrustedClaimIssuer)(issuer, context);
                return {
                    identity: new internal_1.DefaultTrustedClaimIssuer({ did, ticker }, context),
                    trustedFor,
                };
            });
            if (callback) {
                return complianceManager.trustedClaimIssuer(rawTicker, issuers => {
                    callback(assembleResult(issuers));
                });
            }
            const claimIssuers = yield complianceManager.trustedClaimIssuer(rawTicker);
            return assembleResult(claimIssuers);
        });
    }
}
exports.TrustedClaimIssuers = TrustedClaimIssuers;
//# sourceMappingURL=TrustedClaimIssuers.js.map