import { hashProjectPath } from '../storage/base-store.js';
import { previewDeleteDecision, executeDeleteDecision } from '../engine/deleter/core.js';
/**
 * Handle delete_decision tool invocation.
 * Supports single or bulk decision deletion.
 */
export async function handleDeleteDecision(params) {
    try {
        const projectId = hashProjectPath(params.projectRoot);
        const decisionIds = Array.isArray(params.decisionId) ? params.decisionId : [params.decisionId];
        const confirm = params.confirm ?? false;
        const force = params.force ?? false;
        if (!confirm) {
            const preview = await previewDeleteDecision(projectId, decisionIds);
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify({
                            ...preview,
                            message: `Preview: ${String(preview.itemsAffected)} decision(s) would be deleted. Set confirm=true to proceed.`,
                        }, null, 2),
                    },
                ],
            };
        }
        const result = await executeDeleteDecision(projectId, decisionIds, force);
        if (!result.success) {
            return {
                content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
                isError: true,
            };
        }
        return {
            content: [
                {
                    type: 'text',
                    text: JSON.stringify({
                        ...result,
                        message: `Successfully deleted ${String(result.itemsAffected)} decision(s).`,
                    }, null, 2),
                },
            ],
        };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        return {
            content: [{ type: 'text', text: `Delete decision failed: ${message}` }],
            isError: true,
        };
    }
}
//# sourceMappingURL=delete-decision.js.map