import { hashProjectPath } from '../storage/base-store.js';
import { executeTrashAction } from '../engine/deleter/trash-manager.js';
/**
 * Handle manage_trash tool invocation.
 * Supports list, restore, and purge actions.
 */
export async function handleManageTrash(params) {
    try {
        const projectId = hashProjectPath(params.projectRoot);
        const result = await executeTrashAction(projectId, params.action, params.itemId);
        // List returns TrashItem[], others return DeleteResult
        if (Array.isArray(result)) {
            const items = result;
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify({
                            action: 'list',
                            items,
                            count: items.length,
                            message: items.length === 0
                                ? 'Trash is empty.'
                                : `Found ${String(items.length)} item(s) in trash.`,
                        }, null, 2),
                    },
                ],
            };
        }
        const deleteResult = result;
        return {
            content: [
                {
                    type: 'text',
                    text: JSON.stringify({
                        ...deleteResult,
                        message: deleteResult.success
                            ? `${params.action} completed successfully.`
                            : `${params.action} failed: ${deleteResult.warnings.join(', ')}`,
                    }, null, 2),
                },
            ],
            isError: !deleteResult.success ? true : undefined,
        };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        return {
            content: [{ type: 'text', text: `Manage trash failed: ${message}` }],
            isError: true,
        };
    }
}
//# sourceMappingURL=manage-trash.js.map