<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST');
header('Access-Control-Allow-Headers: Content-Type');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $input = file_get_contents('php://input');
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://zwomrn9e98.execute-api.us-east-2.amazonaws.com/v1/get-report');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $input);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Content-Type: application/json',
        'X-API-Key: noW4fiauTE1RrsQ5IXBKo8dp5m4u42CY6JDyItv1'
    ]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $response = curl_exec($ch);
    curl_close($ch);
    
    // Log all responses
    $logEntry = date('Y-m-d H:i:s') . ' - REQUEST: ' . $input . ' - RESPONSE: ' . $response . "\n";
    file_put_contents('api_responses.log', $logEntry, FILE_APPEND | LOCK_EX);
    
    echo $response;
}
?>