"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.initApiQueueWithUidCheck = void 0;
const util_1 = require("@polkadot/util");
const hasUidClaim_1 = require("./hasUidClaim");
const getUidProofFromWallet_1 = require("./getUidProofFromWallet");
const buildApiQueueItem_1 = require("./buildApiQueueItem");
exports.initApiQueueWithUidCheck = ({ sdk, did, polyWallet, ticker, condition = true, proofErrorHandler, }) => __awaiter(void 0, void 0, void 0, function* () {
    const directApiQueue = [];
    if (!condition)
        return directApiQueue;
    const hasUidAttestation = yield hasUidClaim_1.hasUidClaim({
        sdk,
        did,
        ticker,
    });
    if (!hasUidAttestation) {
        const proofObj = yield getUidProofFromWallet_1.getUidProofFromWallet({
            polyWallet,
            ticker,
            errorHandler: proofErrorHandler,
        });
        if (!proofObj)
            throw Error('Faild to get proof from wallet.');
        const { scope_id: scopeId, cdd_id: cddId, proof } = proofObj;
        const tickerHex = util_1.stringToHex(ticker);
        directApiQueue.push(buildApiQueueItem_1.buildApiQueueItem({
            method: sdk._polkadotApi.tx.identity.addInvestorUniquenessClaim,
            params: [
                did,
                {
                    InvestorUniqueness: [{ Ticker: tickerHex }, scopeId, cddId],
                },
                proof,
                null,
            ],
        }));
    }
    return directApiQueue;
});
//# sourceMappingURL=initApiQueueWithUidCheck.js.map