import { hashProjectPath } from '../storage/base-store.js';
import { previewDeleteSpec, executeDeleteSpec } from '../engine/deleter/core.js';
import { ti } from '../i18n/index.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: ti('tools.delete_spec.preview', { count: String(preview.itemsAffected) }),
                        }, 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: ti('tools.delete_spec.success', { count: String(result.itemsAffected) }),
                    }, null, 2),
                },
            ],
        };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        return {
            content: [{ type: 'text', text: ti('tools.delete_spec.error', { message }) }],
            isError: true,
        };
    }
}
//# sourceMappingURL=delete-spec.js.map