/**
 * Pipeline step: Validate configuration.
 *
 * Wraps the existing validateConfiguration() + checkEnvironment() logic
 * behind the PipelineStep interface.
 */
import { checkEnvironment } from "../../pipeline/checks.js";
import { validateConfiguration } from "../../pipeline/validate.js";
export class ValidateStep {
    name = "validate";
    check() {
        // Validation step has no preconditions — it IS the precondition check.
        return [];
    }
    async execute(ctx) {
        const start = Date.now();
        const validation = validateConfiguration(ctx.config.rootDir);
        const envIssues = checkEnvironment(ctx.config.rootDir);
        validation.issues.push(...envIssues);
        const errors = validation.issues.filter((i) => i.severity === "error");
        const warnings = validation.issues.filter((i) => i.severity === "warning");
        for (const w of warnings) {
            ctx.logger.warn(`[${w.source}] ${w.message}`);
        }
        if (errors.length > 0) {
            for (const e of errors) {
                ctx.logger.error(`[${e.source}] ${e.message}${e.path ? ` at ${e.path}` : ""}`);
            }
            return {
                durationMs: Date.now() - start,
                error: `Configuration invalid: ${errors.length} error(s)`,
                status: "failed",
            };
        }
        return {
            durationMs: Date.now() - start,
            status: "success",
            summary: `Configuration valid (${warnings.length} warning(s))`,
        };
    }
}
