import { completeAgent, } from "../../../usecases/mcp/completeAgent.usecase.js";
function isValidStatus(status) {
    return status === "success" || status === "failed";
}
export function createCompleteAgentHandler(deps) {
    return (args) => {
        const jobId = args.jobId;
        const agentName = args.agentName;
        const status = args.status;
        const error = args.error;
        if (typeof jobId !== "string" || !jobId) {
            return {
                content: [{ type: "text", text: "Error: jobId is required" }],
                isError: true,
            };
        }
        if (typeof agentName !== "string" || !agentName) {
            return {
                content: [{ type: "text", text: "Error: agentName is required" }],
                isError: true,
            };
        }
        if (!status) {
            return {
                content: [{ type: "text", text: "Error: status is required" }],
                isError: true,
            };
        }
        if (!isValidStatus(status)) {
            return {
                content: [
                    { type: "text", text: "Error: status must be 'success' or 'failed'" },
                ],
                isError: true,
            };
        }
        const errorMessage = typeof error === "string" && error ? error : undefined;
        const result = completeAgent(jobId, agentName, status, errorMessage, deps);
        if (!result.success) {
            return {
                content: [{ type: "text", text: `Error: ${result.error}` }],
                isError: true,
            };
        }
        return {
            content: [
                {
                    type: "text",
                    text: JSON.stringify({
                        success: true,
                        agentName: result.agentName,
                        status: result.status,
                        completedAt: result.completedAt.toISOString(),
                        overallProgress: result.overallProgress,
                        ...(result.error && { error: result.error }),
                    }, null, 2),
                },
            ],
        };
    };
}
//# sourceMappingURL=completeAgent.handler.js.map