"use strict";
// SPDX-License-Identifier: Apache-2.0
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
require("../environmentMock");
const config_1 = require("../../config");
const ConnectRequest_1 = __importStar(require("../../../src/port/in/request/network/ConnectRequest"));
const ethers_1 = require("ethers");
const RPCTransactionAdapter_1 = require("../../../src/port/out/rpc/RPCTransactionAdapter");
const NetworkService_1 = __importDefault(require("../../../src/app/service/network/NetworkService"));
const MirrorNodeAdapter_1 = require("../../../src/port/out/mirror/MirrorNodeAdapter");
const RPCQueryAdapter_1 = require("../../../src/port/out/rpc/RPCQueryAdapter");
const Injectable_1 = __importDefault(require("../../../src/core/injectable/Injectable"));
const RegulationType_1 = require("../../../src/domain/context/factory/RegulationType");
const in_1 = require("../../../src/port/in");
in_1.SDK.log = { level: "ERROR", transports: new in_1.LoggerTransports.Console() };
const regulationType = RegulationType_1.RegulationType.REG_S;
const regulationSubType = RegulationType_1.RegulationSubType.NONE;
const mirrorNode = {
    name: "testmirrorNode",
    baseUrl: "https://testnet.mirrornode.hedera.com/api/v1/",
};
const rpcNode = {
    name: "testrpcNode",
    baseUrl: "http://127.0.0.1:7546/api",
};
describe("🧪 Factory test", () => {
    let th;
    let ns;
    let mirrorNodeAdapter;
    let rpcQueryAdapter;
    beforeAll(async () => {
        mirrorNodeAdapter = Injectable_1.default.resolve(MirrorNodeAdapter_1.MirrorNodeAdapter);
        mirrorNodeAdapter.set(mirrorNode);
        th = Injectable_1.default.resolve(RPCTransactionAdapter_1.RPCTransactionAdapter);
        ns = Injectable_1.default.resolve(NetworkService_1.default);
        rpcQueryAdapter = Injectable_1.default.resolve(RPCQueryAdapter_1.RPCQueryAdapter);
        rpcQueryAdapter.init();
        ns.environment = "testnet";
        ns.configuration = {
            factoryAddress: config_1.FACTORY_ADDRESS,
            resolverAddress: config_1.RESOLVER_ADDRESS,
        };
        ns.mirrorNode = mirrorNode;
        ns.rpcNode = rpcNode;
        await th.init(true);
        await th.register(undefined, true);
        const url = "http://127.0.0.1:7546";
        const customHttpProvider = new ethers_1.ethers.JsonRpcProvider(url);
        th.setSignerOrProvider(new ethers_1.Wallet(config_1.CLIENT_ACCOUNT_ECDSA.privateKey?.key ?? "", customHttpProvider));
        await in_1.Network.connect(new ConnectRequest_1.default({
            account: {
                accountId: config_1.CLIENT_ACCOUNT_ECDSA.id.toString(),
                privateKey: config_1.CLIENT_ACCOUNT_ECDSA.privateKey,
            },
            network: "testnet",
            wallet: ConnectRequest_1.SupportedWallets.METAMASK,
            mirrorNode: mirrorNode,
            rpcNode: rpcNode,
            debug: true,
        }));
    }, 600_000);
    it("Check Regulation Details", async () => {
        const regulationDetails = await in_1.Factory.getRegulationDetails(new in_1.GetRegulationDetailsRequest({
            regulationType: RegulationType_1.CastRegulationType.toNumber(regulationType),
            regulationSubType: RegulationType_1.CastRegulationSubType.toNumber(regulationSubType),
        }));
        expect(regulationDetails.type).toEqual(regulationType);
        expect(regulationDetails.subType).toEqual(regulationSubType);
        expect(regulationDetails.accreditedInvestors).toEqual("ACCREDITATION REQUIRED");
        expect(regulationDetails.dealSize).toEqual("0");
        expect(regulationDetails.internationalInvestors).toEqual("ALLOWED");
        expect(regulationDetails.manualInvestorVerification).toEqual("VERIFICATION INVESTORS FINANCIAL DOCUMENTS REQUIRED");
        expect(regulationDetails.maxNonAccreditedInvestors).toEqual(0);
        expect(regulationDetails.resaleHoldPeriod).toEqual("NOT APPLICABLE");
    }, 60_000);
});
