import { hashProjectPath } from '../storage/base-store.js';
import { previewDeletePattern, executeDeletePattern } from '../engine/deleter/core.js';
/**
 * Handle delete_pattern tool invocation.
 * Supports single or bulk pattern deletion.
 */
export async function handleDeletePattern(params) {
    try {
        const projectId = hashProjectPath(params.projectRoot);
        const patternIds = Array.isArray(params.patternId) ? params.patternId : [params.patternId];
        const confirm = params.confirm ?? false;
        const force = params.force ?? false;
        if (!confirm) {
            const preview = await previewDeletePattern(projectId, patternIds);
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify({
                            ...preview,
                            message: `Preview: ${String(preview.itemsAffected)} pattern(s) would be deleted. Set confirm=true to proceed.`,
                        }, null, 2),
                    },
                ],
            };
        }
        const result = await executeDeletePattern(projectId, patternIds, 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)} pattern(s).`,
                    }, null, 2),
                },
            ],
        };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        return {
            content: [{ type: 'text', text: `Delete pattern failed: ${message}` }],
            isError: true,
        };
    }
}
//# sourceMappingURL=delete-pattern.js.map