import { prisma } from '../lib/prisma';
import { lexofficeService } from '../lib/lexoffice';

async function main() {
  console.log('🔄 Finalisiere bestehende Quotation...\n');

  const quotationId = 'c66b3347-4411-449c-897f-e0d84cb42601';

  try {
    console.log('📤 Rufe PUT /quotations/{id}/pursue auf...');
    const result = await lexofficeService.finalizeQuotation(quotationId);
    console.log('✅ Erfolgreich!', result);

    console.log('\n🔍 Prüfe neuen Status...');
    const quotation = await lexofficeService.getQuotation(quotationId);
    console.log('Status:', quotation.voucherStatus);

    console.log('\n📄 Versuche PDF Download...');
    const pdf = await lexofficeService.getQuotationPDF(quotationId);
    console.log('✅ PDF erfolgreich! Größe:', pdf.length, 'bytes');
    
  } catch (error: any) {
    console.error('❌ Fehler:', error.message);
    console.error('Details:', error);
  }
}

main()
  .catch((e) => {
    console.error(e);
    process.exit(1);
  })
  .finally(async () => {
    await prisma.$disconnect();
  });
