// 简单的测试脚本来验证docxtemplater合并功能
import { DocumentService } from './src/server/modules/documents/document.service.js';
import { DataSource } from 'typeorm';

// 创建模拟的DataSource
const mockDataSource = {};

async function testMerge() {
  console.log('Testing docxtemplater merge functionality...');
  
  const documentService = new DocumentService(mockDataSource);
  
  // 创建一些模拟的Word文档缓冲区
  const mockDoc1 = Buffer.from('Mock Word Document 1');
  const mockDoc2 = Buffer.from('Mock Word Document 2');
  
  try {
    console.log('Testing mergeWordDocuments method...');
    
    const result = await documentService.mergeWordDocuments(
      [mockDoc1, mockDoc2],
      {
        preserveFormatting: true,
        outputFormat: 'docx'
      }
    );
    
    console.log('✅ Merge successful!');
    console.log(`Result buffer size: ${result.length} bytes`);
    console.log(`MinIO available: ${documentService.isMinioAvailable()}`);
    
    // 测试保存到MinIO（回退到base64）
    const downloadUrl = await documentService.saveToMinio(result, 'test.docx');
    console.log(`Download URL: ${downloadUrl.substring(0, 100)}...`);
    
  } catch (error) {
    console.error('❌ Merge failed:', error.message);
  }
}

testMerge().catch(console.error);