<?php
/**
 * IXLARGE — Dinamik Sitemap
 * Bu dosya doğrudan erişilebilir, XML çıktısı verir.
 */

declare(strict_types=1);

require_once __DIR__ . '/core/App.php';

$app = App::getInstance();

// Cache'den kontrol et
$cacheKey = 'sitemap_xml';
$cached = Cache::get($cacheKey);

if ($cached !== null) {
    header('Content-Type: application/xml; charset=utf-8');
    header('X-Cache: HIT');
    echo $cached;
    exit;
}

try {
    $sitemapService = new SitemapService();
    $xml = $sitemapService->generate();

    // 12 saat cache
    Cache::set($cacheKey, $xml, 43200);

    header('Content-Type: application/xml; charset=utf-8');
    header('X-Cache: MISS');
    echo $xml;
} catch (\Exception $e) {
    header('Content-Type: application/xml; charset=utf-8');
    echo '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></urlset>';
}