<?php

declare(strict_types=1);

require_once __DIR__ . '/../../vendor/autoload.php';

use App\Framework\Core\ValueObjects\Hash;
use App\Framework\Core\ValueObjects\HashAlgorithm;
use App\Framework\UserAgent\UserAgentParser;

echo "=== Testing Hash Value Object Integration ===\n\n";

// Test 1: Hash VO mit xxh3
echo "Test 1: Hash VO with xxh3 algorithm\n";
echo "-----------------------------------\n";
$data = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0";
$hash = Hash::create($data, HashAlgorithm::XXHASH3);
echo "Data: {$data}\n";
echo "Algorithm: " . $hash->getAlgorithm()->value . "\n";
echo "Hash: " . $hash->toString() . "\n";
echo "Hash Length: " . strlen($hash->toString()) . "\n\n";

// Test 2: HashAlgorithm::fast()
echo "Test 2: HashAlgorithm::fast() method\n";
echo "-----------------------------------\n";
$fastAlgo = HashAlgorithm::fast();
echo "Fast Algorithm: " . $fastAlgo->value . "\n";
echo "Is xxh3 available: " . (HashAlgorithm::XXHASH3->isAvailable() ? 'Yes' : 'No') . "\n";
echo "Is xxh64 available: " . (HashAlgorithm::XXHASH64->isAvailable() ? 'Yes' : 'No') . "\n\n";

// Test 3: UserAgentParser mit Hash VO
echo "Test 3: UserAgentParser using Hash VO\n";
echo "-----------------------------------\n";
$parser = new UserAgentParser();
$ua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 Chrome/120.0.0.0";
$parsed = $parser->parse($ua);

echo "User-Agent: {$ua}\n";
echo "Browser: " . $parsed->browser->getDisplayName() . "\n";
echo "Browser Version: " . $parsed->browserVersion->toString() . "\n";
echo "Platform: " . $parsed->platform->getDisplayName() . "\n";
echo "Platform Version: " . $parsed->platformVersion->toString() . "\n";
echo "Engine: " . $parsed->engine->getDisplayName() . "\n";
echo "Is Modern: " . ($parsed->isModern ? 'Yes' : 'No') . "\n\n";

// Test 4: Hash comparison
echo "Test 4: Hash equality check\n";
echo "-----------------------------------\n";
$hash1 = Hash::create("test data", HashAlgorithm::XXHASH3);
$hash2 = Hash::create("test data", HashAlgorithm::XXHASH3);
$hash3 = Hash::create("different data", HashAlgorithm::XXHASH3);

echo "Hash1 equals Hash2: " . ($hash1->equals($hash2) ? 'Yes' : 'No') . "\n";
echo "Hash1 equals Hash3: " . ($hash1->equals($hash3) ? 'Yes' : 'No') . "\n\n";

// Test 5: Available hash algorithms
echo "Test 5: Available hash algorithms\n";
echo "-----------------------------------\n";
foreach (HashAlgorithm::cases() as $algo) {
    $available = $algo->isAvailable() ? '✓' : '✗';
    $secure = $algo->isSecure() ? '(secure)' : '(fast)';
    echo "{$available} {$algo->value} - Length: {$algo->getLength()} chars {$secure}\n";
}

echo "\n=== All Tests Completed Successfully ===\n";
