// engine/infrastructure/index.ts — Main orchestrator for generate_infrastructure (SPEC-171)
import { detectInfraSignals } from './signal-detector.js';
import { mapSignalsToComponents } from './component-mapper.js';
import { estimateCosts } from './cost-estimator.js';
import { generateTerraform } from './terraform-generator.js';
import { generateDockerCompose } from './docker-compose-generator.js';
import { generateKubernetes } from './kubernetes-generator.js';
import { generateRailway } from './railway-generator.js';
// Re-export submodules for barrel access
export { detectInfraSignals } from './signal-detector.js';
export { mapSignalsToComponents } from './component-mapper.js';
export { estimateCosts } from './cost-estimator.js';
export { generateTerraform } from './terraform-generator.js';
export { generateDockerCompose } from './docker-compose-generator.js';
export { generateKubernetes } from './kubernetes-generator.js';
export { generateRailway } from './railway-generator.js';
const DEFAULT_FORMATS = ['terraform', 'docker-compose'];
const FORMAT_GENERATORS = {
    terraform: generateTerraform,
    'docker-compose': generateDockerCompose,
    kubernetes: generateKubernetes,
    railway: generateRailway,
};
/**
 * Main entry point — generates IaC files from a spec text body.
 * @param input - Tool input (projectId, specId, formats, environment)
 * @param specText - Full text content of the spec to analyze
 */
export function generateInfrastructure(input, specText) {
    const env = input.environment ?? 'dev';
    const formats = input.formats ?? DEFAULT_FORMATS;
    const warnings = [];
    // Phase 1: signal detection
    const signals = detectInfraSignals(specText);
    if (signals.length === 0) {
        warnings.push('No infrastructure signals detected in the spec. ' +
            'Add mentions of databases, queues, caches, storage, or deployment targets ' +
            'to generate meaningful IaC output.');
    }
    // Phase 2: map signals to components
    const components = mapSignalsToComponents(signals, env);
    // Phase 3: estimate costs (mutates component.estimatedMonthlyCostUsd in place)
    const costEstimate = estimateCosts(components, env);
    // Phase 4: generate requested formats
    const files = [];
    for (const format of formats) {
        const generator = FORMAT_GENERATORS[format];
        try {
            const output = generator(components, env);
            files.push(output);
        }
        catch (err) {
            const msg = err instanceof Error ? err.message : String(err);
            warnings.push(`Failed to generate ${format}: ${msg}`);
        }
    }
    return {
        specId: input.specId,
        environment: env,
        signalsDetected: signals,
        components,
        files,
        costEstimate,
        warnings,
    };
}
//# sourceMappingURL=index.js.map