public with sharing class TestAPICall {
    
    @AuraEnabled
    public static String testPythonAPI() {
        try {
            // Test with minimal HTML to see what the Python server returns
            String testHtml = '<html><body><h1>Test</h1><p>Small test content</p></body></html>';
            
            Http http = new Http();
            HttpRequest request = new HttpRequest();
            request.setEndpoint('https://salesforce.tech4biz.io/generate-pdf');
            request.setMethod('POST');
            request.setHeader('Content-Type', 'application/json');
            request.setHeader('Accept', 'application/json');
            
            Map<String, Object> requestBody = new Map<String, Object>();
            requestBody.put('html_content', testHtml);
            requestBody.put('pageSize', 'A4');
            requestBody.put('filename', 'test.pdf');
            requestBody.put('return_download_link', true); // CRITICAL: Request download link only
            requestBody.put('store_on_server', true);
            requestBody.put('pdf_id', 'TEST_' + DateTime.now().getTime());
            
            String jsonBody = JSON.serialize(requestBody);
            request.setBody(jsonBody);
            request.setTimeout(30000);
            
            HttpResponse response = http.send(request);
            
            System.debug('Response Status: ' + response.getStatusCode());
            System.debug('Response Body Length: ' + response.getBody().length());
            System.debug('Response Body: ' + response.getBody());
            
            if (response.getBody().length() > 1000000) { // 1MB
                return 'ERROR: Response too large (' + response.getBody().length() + ' bytes). Python server is returning PDF content instead of download link.';
            }
            
            return 'SUCCESS: Response size is ' + response.getBody().length() + ' bytes. Response: ' + response.getBody();
            
        } catch (Exception e) {
            return 'ERROR: ' + e.getMessage();
        }
    }
}
