"use strict";
/**
 * Plugin registry and factory.
 *
 * Maps plugin names to constructors and creates the ordered plugin list
 * from a BenchmarkConfig.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.createPluginsFromConfig = createPluginsFromConfig;
const turn_counter_1 = require("./turn-counter");
const token_tracker_1 = require("./token-tracker");
const cache_tracker_1 = require("./cache-tracker");
const compaction_tracker_1 = require("./compaction-tracker");
const context_size_tracker_1 = require("./context-size-tracker");
const cost_tracker_1 = require("./cost-tracker");
const duration_tracker_1 = require("./duration-tracker");
const summary_1 = require("./summary");
const json_writer_1 = require("./json-writer");
const PLUGIN_REGISTRY = {
    turns: () => new turn_counter_1.TurnCounterPlugin(),
    tokens: () => new token_tracker_1.TokenTrackerPlugin(),
    cache: () => new cache_tracker_1.CacheTrackerPlugin(),
    compactions: () => new compaction_tracker_1.CompactionTrackerPlugin(),
    contextSize: () => new context_size_tracker_1.ContextSizeTrackerPlugin(),
    cost: () => new cost_tracker_1.CostTrackerPlugin(),
    duration: () => new duration_tracker_1.DurationTrackerPlugin(),
    summary: (opts) => {
        if (!opts.spinner)
            throw new Error('SummaryPlugin requires a spinner');
        return new summary_1.SummaryPlugin(opts.spinner);
    },
    jsonWriter: (opts) => {
        if (!opts.outputPath)
            throw new Error('JsonWriterPlugin requires outputPath');
        return new json_writer_1.JsonWriterPlugin(opts.outputPath);
    },
};
/**
 * Execution order — data producers before consumers:
 * turns (dedup) -> tokens -> cache -> compactions -> contextSize -> cost -> duration -> summary -> jsonWriter
 */
const PLUGIN_ORDER = [
    'turns',
    'tokens',
    'cache',
    'compactions',
    'contextSize',
    'cost',
    'duration',
    'summary',
    'jsonWriter',
];
function createPluginsFromConfig(config, opts) {
    const resolvedOpts = {
        ...opts,
        outputPath: opts.outputPath ?? config.output.benchmarkPath,
    };
    // If suppressWizardLogs is set, disable the summary plugin
    const effectivePlugins = { ...config.plugins };
    if (config.output.suppressWizardLogs) {
        effectivePlugins.summary = false;
    }
    return PLUGIN_ORDER.filter((name) => effectivePlugins[name] !== false)
        .map((name) => PLUGIN_REGISTRY[name])
        .filter(Boolean)
        .map((factory) => factory(resolvedOpts));
}
