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