"use strict";
// SPDX-License-Identifier: Apache-2.0
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var Injectable_1;
Object.defineProperty(exports, "__esModule", { value: true });
const tsyringe_1 = require("tsyringe");
const RPCTransactionAdapter_1 = require("../../port/out/rpc/RPCTransactionAdapter");
const WalletEvent_1 = require("../../app/service/event/WalletEvent");
const RuntimeError_1 = require("../error/RuntimeError");
const Common_1 = require("../../port/in/Common");
const HederaWalletConnectTransactionAdapter_1 = require("../../port/out/hs/walletconnect/HederaWalletConnectTransactionAdapter");
const DFNSTransactionAdapter_1 = require("../../port/out/hs/custodial/DFNSTransactionAdapter");
const FireblocksTransactionAdapter_1 = require("../../port/out/hs/custodial/FireblocksTransactionAdapter");
const AWSKMSTransactionAdapter_1 = require("../../port/out/hs/custodial/AWSKMSTransactionAdapter");
const Tokens_1 = require("./Tokens");
const Handlers_1 = require("./Handlers");
const defaultNetworkProps = {
    environment: "testnet",
    mirrorNode: {
        name: "default",
        baseUrl: "https://testnet.mirrornode.hedera.com",
    },
    rpcNode: {
        name: "default",
        baseUrl: "https://testnet.hashio.io/api",
    },
};
// Network default props
tsyringe_1.container.register("NetworkProps", {
    useValue: defaultNetworkProps,
});
// Wallet events
tsyringe_1.container.register("WalletEvents", {
    useValue: WalletEvent_1.WalletEvents,
});
// SDK Logs
tsyringe_1.container.register("SDK", {
    useValue: Common_1.SDK,
});
let Injectable = class Injectable {
    static { Injectable_1 = this; }
    static TOKENS = Tokens_1.TOKENS;
    static currentTransactionHandler;
    static resolve(cls) {
        return tsyringe_1.container.resolve(cls);
    }
    static lazyResolve(cls) {
        return tsyringe_1.container.resolve((0, tsyringe_1.delay)(() => cls));
    }
    static getQueryHandlers() {
        return tsyringe_1.container.resolveAll(Tokens_1.TOKENS.QUERY_HANDLER);
    }
    static getCommandHandlers() {
        return tsyringe_1.container.resolveAll(Tokens_1.TOKENS.COMMAND_HANDLER);
    }
    static register(token, value) {
        return tsyringe_1.container.register(token, value);
    }
    static registerCommandHandler(cls) {
        return tsyringe_1.container.register(Tokens_1.TOKENS.COMMAND_HANDLER, cls);
    }
    static registerTransactionHandler(cls) {
        if (this.currentTransactionHandler)
            this.currentTransactionHandler.stop();
        this.currentTransactionHandler = cls;
        return true;
    }
    static resolveTransactionHandler() {
        if (!this.currentTransactionHandler) {
            throw new RuntimeError_1.RuntimeError("No Transaction Handler registered!");
        }
        else {
            return this.currentTransactionHandler;
        }
    }
    static registerTransactionAdapterInstances() {
        const adapters = [];
        if (this.isWeb()) {
            adapters.push(Injectable_1.resolve(RPCTransactionAdapter_1.RPCTransactionAdapter), Injectable_1.resolve(HederaWalletConnectTransactionAdapter_1.HederaWalletConnectTransactionAdapter));
        }
        adapters.push(Injectable_1.resolve(DFNSTransactionAdapter_1.DFNSTransactionAdapter), Injectable_1.resolve(FireblocksTransactionAdapter_1.FireblocksTransactionAdapter), Injectable_1.resolve(AWSKMSTransactionAdapter_1.AWSKMSTransactionAdapter));
        return adapters;
    }
    static isWeb() {
        return !!global.window;
    }
};
Injectable = Injectable_1 = __decorate([
    (0, tsyringe_1.registry)([...Handlers_1.COMMAND_HANDLERS, ...Handlers_1.QUERY_HANDLERS, ...Handlers_1.TRANSACTION_HANDLER])
], Injectable);
exports.default = Injectable;
