"use strict";
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 BlocksQueueModule_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BlocksQueueModule = void 0;
const common_1 = require("@nestjs/common");
const blockchain_provider_service_1 = require("../blockchain-provider/blockchain-provider.service");
const blocks_queue_service_1 = require("./blocks-queue.service");
const blocks_iterator_service_1 = require("./blocks-iterator/blocks-iterator.service");
const blocks_loader_service_1 = require("./blocks-loader/blocks-loader.service");
const mempool_loader_service_1 = require("./mempool-loader.service");
let BlocksQueueModule = BlocksQueueModule_1 = class BlocksQueueModule {
    static async forRootAsync(config) {
        const { blocksCommandExecutor, mempoolCommandExecutor, mempoolLoaderStrategyName = 'subscribe-ws', tracesEnabled = false, verifyTrie = false, ...restConfig } = config;
        return {
            module: BlocksQueueModule_1,
            imports: [],
            providers: [
                {
                    provide: 'BlocksCommandExecutor',
                    useClass: blocksCommandExecutor,
                },
                {
                    provide: 'MempoolCommandExecutor',
                    useClass: mempoolCommandExecutor,
                },
                {
                    provide: blocks_iterator_service_1.BlocksQueueIteratorService,
                    useFactory: (executor, blockchainProvider) => new blocks_iterator_service_1.BlocksQueueIteratorService(executor, blockchainProvider, { ...restConfig }),
                    inject: ['BlocksCommandExecutor', blockchain_provider_service_1.BlockchainProviderService],
                },
                {
                    provide: mempool_loader_service_1.MempoolLoaderService,
                    useFactory: (provider, executor) => new mempool_loader_service_1.MempoolLoaderService(provider, executor, mempoolLoaderStrategyName),
                    inject: [blockchain_provider_service_1.BlockchainProviderService, 'MempoolCommandExecutor'],
                },
                {
                    provide: blocks_loader_service_1.BlocksQueueLoaderService,
                    useFactory: (provider, mempoolService) => new blocks_loader_service_1.BlocksQueueLoaderService(provider, mempoolService, { ...restConfig, tracesEnabled, verifyTrie }),
                    inject: [blockchain_provider_service_1.BlockchainProviderService, mempool_loader_service_1.MempoolLoaderService],
                },
                {
                    provide: blocks_queue_service_1.BlocksQueueService,
                    useFactory: (iterator, loader, mempoolService, blockchainProvider) => new blocks_queue_service_1.BlocksQueueService(iterator, loader, mempoolService, blockchainProvider, {
                        ...restConfig,
                        tracesEnabled,
                        verifyTrie,
                    }),
                    inject: [
                        blocks_iterator_service_1.BlocksQueueIteratorService,
                        blocks_loader_service_1.BlocksQueueLoaderService,
                        mempool_loader_service_1.MempoolLoaderService,
                        blockchain_provider_service_1.BlockchainProviderService,
                    ],
                },
            ],
            exports: [blocks_queue_service_1.BlocksQueueService, mempool_loader_service_1.MempoolLoaderService],
        };
    }
};
exports.BlocksQueueModule = BlocksQueueModule;
exports.BlocksQueueModule = BlocksQueueModule = BlocksQueueModule_1 = __decorate([
    (0, common_1.Module)({})
], BlocksQueueModule);
