import { fromHex, toPrintableUrl } from "@lodestar/utils";
import { ExecutionEngineDisabled } from "./disabled.js";
import { ExecutionEngineHttp, defaultExecutionEngineHttpOpts, } from "./http.js";
import { JsonRpcHttpClient } from "./jsonRpcHttpClient.js";
import { ExecutionEngineMockBackend } from "./mock.js";
import { ExecutionEngineMockJsonRpcClient } from "./utils.js";
export { ExecutionEngineHttp, ExecutionEngineDisabled, defaultExecutionEngineHttpOpts };
export const defaultExecutionEngineOpts = defaultExecutionEngineHttpOpts;
export function getExecutionEngineFromBackend(backend, modules) {
    const rpc = new ExecutionEngineMockJsonRpcClient(backend);
    return new ExecutionEngineHttp(rpc, modules);
}
export function getExecutionEngineHttp(opts, modules) {
    const rpc = new JsonRpcHttpClient(opts.urls, {
        ...opts,
        signal: modules.signal,
        metrics: modules.metrics?.executionEnginerHttpClient,
        jwtSecret: opts.jwtSecretHex ? fromHex(opts.jwtSecretHex) : undefined,
        jwtId: opts.jwtId,
        jwtVersion: opts.jwtVersion,
    });
    modules.logger.info("Execution client", { urls: opts.urls.map(toPrintableUrl).toString() });
    return new ExecutionEngineHttp(rpc, modules, opts);
}
export function initializeExecutionEngine(opts, modules) {
    switch (opts.mode) {
        case "disabled":
            return new ExecutionEngineDisabled();
        case "mock":
            return getExecutionEngineFromBackend(new ExecutionEngineMockBackend(opts), modules);
        case "http":
            return getExecutionEngineHttp(opts, modules);
        default:
            return getExecutionEngineHttp(opts, modules);
    }
}
//# sourceMappingURL=index.js.map