import { hashProjectPath } from '../storage/base-store.js';
import { executeTrashAction } from '../engine/deleter/trash-manager.js';
import { t, ti } from '../i18n/index.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
                                ? t('tools.manage_trash.emptyTrash')
                                : ti('tools.manage_trash.itemsFound', { count: String(items.length) }),
                        }, null, 2),
                    },
                ],
            };
        }
        const deleteResult = result;
        return {
            content: [
                {
                    type: 'text',
                    text: JSON.stringify({
                        ...deleteResult,
                        message: deleteResult.success
                            ? ti('tools.manage_trash.actionSuccess', { action: params.action })
                            : ti('tools.manage_trash.actionFailed', {
                                action: params.action,
                                details: 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: ti('tools.manage_trash.error', { message }) }],
            isError: true,
        };
    }
}
//# sourceMappingURL=manage-trash.js.map