import React from "react";
import { OperationPanel, validationPanelModel } from "../../components/OperationPanel.js";
import { ValidationService } from "../../services/validation/validationService.js";
import { resolveRunId } from "../runSelection.js";
const STATUSES = new Set(["pending", "passed", "failed"]);
export const validationCommand = {
    name: "validation",
    description: "List artifact validation gates.",
    usage: "[run-id|attached] [pending|passed|failed]",
    execute(args, context) {
        const parts = args.trim().split(/\s+/).filter(Boolean);
        const statusArg = parts.find((part) => STATUSES.has(part));
        const status = statusArg;
        const runArg = parts.find((part) => part !== statusArg) || "";
        const runId = runArg ? resolveRunId(runArg, context) : undefined;
        const gates = new ValidationService(context.state).list(runId, status);
        const scope = [runId ?? "all", status ?? "any"].join(" ");
        const display = React.createElement(OperationPanel, { model: validationPanelModel(gates, scope) });
        if (gates.length === 0)
            return { message: "No validation gates.", display };
        return {
            message: gates
                .map((gate, index) => `${index + 1}. ${gate.status} validation\n   target: ${gate.subjectType}:${gate.subjectId}\n   ${gate.summary}`)
                .join("\n"),
            display,
        };
    },
};
