const http = require('http');

// Test making a customer payment to reduce outstanding balance
const paymentData = JSON.stringify({
    customer_id: 1,
    payment_date: "2026-01-28",
    amount_paid: 50,
    notes: "Test payment reduction"
});

const options = {
    hostname: 'localhost',
    port: 3000,
    path: '/api/customer-payments',
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Content-Length': Buffer.byteLength(paymentData)
    }
};

const req = http.request(options, (res) => {
    let data = '';
    res.on('data', chunk => data += chunk);
    res.on('end', () => {
        console.log('Payment response:', data);
        
        // Check customer credit after payment
        http.get('http://localhost:3000/api/customers', (res) => {
            let data = '';
            res.on('data', chunk => data += chunk);
            res.on('end', () => {
                console.log('Customers after payment:', data);
            });
        });
    });
});

req.on('error', (error) => {
    console.error('Error:', error);
});

req.write(paymentData);
req.end();