import { LexOfficeService } from '../lib/lexoffice';

async function main() {
  const lexoffice = new LexOfficeService();

  console.log('🧪 Teste LexOffice Quotation finalize Parameter...\n');

  // Einfaches Test-Angebot erstellen
  const testQuotation = {
    voucherDate: new Date().toISOString().split('T')[0] + 'T00:00:00.000+01:00',
    expirationDate: new Date(Date.now() + 14 * 24 * 60 * 60 * 1000).toISOString().split('T')[0] + 'T00:00:00.000+01:00',
    address: {
      name: 'Test Kunde',
      countryCode: 'DE',
    },
    lineItems: [
      {
        type: 'custom' as const,
        name: 'Test Artikel',
        quantity: 1,
        unitName: 'Stück',
        unitPrice: {
          currency: 'EUR',
          netAmount: 100,
          taxRatePercentage: 19,
        },
      },
    ],
    totalPrice: {
      currency: 'EUR',
    },
    taxConditions: {
      taxType: 'net' as const,
    },
  };

  try {
    console.log('📤 Erstelle Quotation MIT finalize=true...');
    const result = await lexoffice.createQuotation(testQuotation, true);
    console.log('✅ Quotation erstellt:', result);

    console.log('\n🔍 Lade Quotation Details...');
    const details = await lexoffice.getQuotation(result.id);
    console.log('📊 Quotation Status:', JSON.stringify(details, null, 2));

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

main();
