// 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;
import { registry, container, delay } from "tsyringe";
import { RPCTransactionAdapter } from "../../port/out/rpc/RPCTransactionAdapter";
import { WalletEvents } from "../../app/service/event/WalletEvent";
import { RuntimeError } from "../error/RuntimeError";
import { SDK } from "../../port/in/Common";
import { HederaWalletConnectTransactionAdapter } from "../../port/out/hs/walletconnect/HederaWalletConnectTransactionAdapter";
import { DFNSTransactionAdapter } from "../../port/out/hs/custodial/DFNSTransactionAdapter";
import { FireblocksTransactionAdapter } from "../../port/out/hs/custodial/FireblocksTransactionAdapter";
import { AWSKMSTransactionAdapter } from "../../port/out/hs/custodial/AWSKMSTransactionAdapter";
import { TOKENS } from "./Tokens";
import { COMMAND_HANDLERS, QUERY_HANDLERS, TRANSACTION_HANDLER } from "./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
container.register("NetworkProps", {
    useValue: defaultNetworkProps,
});
// Wallet events
container.register("WalletEvents", {
    useValue: WalletEvents,
});
// SDK Logs
container.register("SDK", {
    useValue: SDK,
});
let Injectable = class Injectable {
    static { Injectable_1 = this; }
    static TOKENS = TOKENS;
    static currentTransactionHandler;
    static resolve(cls) {
        return container.resolve(cls);
    }
    static lazyResolve(cls) {
        return container.resolve(delay(() => cls));
    }
    static getQueryHandlers() {
        return container.resolveAll(TOKENS.QUERY_HANDLER);
    }
    static getCommandHandlers() {
        return container.resolveAll(TOKENS.COMMAND_HANDLER);
    }
    static register(token, value) {
        return container.register(token, value);
    }
    static registerCommandHandler(cls) {
        return container.register(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("No Transaction Handler registered!");
        }
        else {
            return this.currentTransactionHandler;
        }
    }
    static registerTransactionAdapterInstances() {
        const adapters = [];
        if (this.isWeb()) {
            adapters.push(Injectable_1.resolve(RPCTransactionAdapter), Injectable_1.resolve(HederaWalletConnectTransactionAdapter));
        }
        adapters.push(Injectable_1.resolve(DFNSTransactionAdapter), Injectable_1.resolve(FireblocksTransactionAdapter), Injectable_1.resolve(AWSKMSTransactionAdapter));
        return adapters;
    }
    static isWeb() {
        return !!global.window;
    }
};
Injectable = Injectable_1 = __decorate([
    registry([...COMMAND_HANDLERS, ...QUERY_HANDLERS, ...TRANSACTION_HANDLER])
], Injectable);
export default Injectable;
