"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());
    });
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultTrustedClaimIssuer = void 0;
const internal_1 = require("../../internal");
const queries_1 = require("../../middleware/queries");
const constants_1 = require("../../utils/constants");
const conversion_1 = require("../../utils/conversion");
const internal_2 = require("../../utils/internal");
/**
 * Represents a default trusted claim issuer for a specific token in the Polymesh blockchain
 */
class DefaultTrustedClaimIssuer extends internal_1.Identity {
    /**
     * @hidden
     */
    constructor(args, context) {
        const { trustedFor, ticker } = args, identifiers = __rest(args, ["trustedFor", "ticker"]);
        super(identifiers, context);
        this.token = new internal_1.SecurityToken({ ticker }, context);
        this.trustedFor = trustedFor;
    }
    /**
     * @hidden
     * Check if a value is of type [[UniqueIdentifiers]]
     */
    static isUniqueIdentifiers(identifier) {
        const { did, ticker } = identifier;
        return typeof did === 'string' && typeof ticker === 'string';
    }
    /**
     * Retrieve the identifier data (block number, date and event index) of the event that was emitted when the trusted claim issuer was added
     *
     * @note uses the middleware
     * @note there is a possibility that the data is not ready by the time it is requested. In that case, `null` is returned
     */
    addedAt() {
        return __awaiter(this, void 0, void 0, function* () {
            const { token: { ticker }, did, context, } = this;
            const { data: { eventByAddedTrustedClaimIssuer: event }, } = yield context.queryMiddleware(queries_1.eventByAddedTrustedClaimIssuer({
                ticker: internal_2.padString(ticker, constants_1.MAX_TICKER_LENGTH),
                identityId: did,
            }));
            return internal_2.optionize(conversion_1.middlewareEventToEventIdentifier)(event);
        });
    }
}
exports.DefaultTrustedClaimIssuer = DefaultTrustedClaimIssuer;
//# sourceMappingURL=DefaultTrustedClaimIssuer.js.map