<?php
require_once 'vendor/autoload.php';

// Create a simple test to verify the service works
echo "=== RMTO Service Test ===\n\n";

// Test 1: Check if class exists
echo "Test 1: Checking if RmtoService class exists...\n";
if (class_exists('App\Services\RmtoService')) {
    echo "✓ RmtoService class found\n";
} else {
    echo "✗ RmtoService class not found\n";
    exit(1);
}

// Test 2: Bootstrap Laravel for config
echo "\nTest 2: Bootstrapping Laravel...\n";
$app = require_once 'bootstrap/app.php';
$app->make('Illuminate\Contracts\Http\Kernel');

// Test 3: Instantiate the service
echo "\nTest 3: Instantiating RmtoService...\n";
try {
    $service = new App\Services\RmtoService();
    echo "✓ RmtoService instantiated successfully\n";
} catch (Exception $e) {
    echo "✗ Error: " . $e->getMessage() . "\n";
    echo "Trace: " . $e->getTraceAsString() . "\n";
    exit(1);
}

// Test 4: Check if getCurrentDate method exists
echo "\nTest 4: Checking if getCurrentDate method exists...\n";
if (method_exists($service, 'getCurrentDate')) {
    echo "✓ getCurrentDate method found\n";
} else {
    echo "✗ getCurrentDate method not found\n";
    exit(1);
}

// Test 5: Test cURL connectivity to RMTO server
echo "\nTest 5: Testing connection to RMTO server...\n";
$ch = curl_init();
curl_setopt_array($ch, [
    CURLOPT_URL => 'http://bar-test.rmto.ir/TRNServiceV03.svc',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 10,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_NOBODY => true,
]);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);

if ($error) {
    echo "✗ Connection error: " . $error . "\n";
} else if ($httpCode === 405) {
    echo "✓ Server is reachable (HTTP " . $httpCode . " - expected, as we're not sending SOAP)\n";
} else {
    echo "✓ Server responded with HTTP " . $httpCode . "\n";
}

echo "\n=== All basic tests passed! ===\n";

