<?php
header('Content-Type: application/xml; charset=utf-8');

// Load data
$data_file = __DIR__ . '/data.json';
$data = json_decode(file_get_contents($data_file), true);

$domain = 'https://desisex.beauty';
$lastmod = date('Y-m-d');

echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' . "\n";
echo '         xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">' . "\n";

// Homepage
echo "  <url>\n";
echo "    <loc>$domain/</loc>\n";
echo "    <lastmod>$lastmod</lastmod>\n";
echo "    <changefreq>daily</changefreq>\n";
echo "    <priority>1.0</priority>\n";
echo "  </url>\n";

// Video pages
foreach ($data as $video_id => $video) {
    $video_url = $domain . '/video-' . urlencode($video_id) . '/';
    $title = htmlspecialchars($video['titleName'] ?? 'Video');
    $description = htmlspecialchars('Watch: ' . ($video['titleName'] ?? 'Premium video'));
    
    echo "  <url>\n";
    echo "    <loc>" . htmlspecialchars($video_url) . "</loc>\n";
    echo "    <lastmod>$lastmod</lastmod>\n";
    echo "    <changefreq>weekly</changefreq>\n";
    echo "    <priority>0.8</priority>\n";
    
    // Video metadata
    echo "    <video:video>\n";
    echo "      <video:title>$title</video:title>\n";
    echo "      <video:description>$description</video:description>\n";
    echo "      <video:thumbnail_loc>$domain/icon.png</video:thumbnail_loc>\n";
    echo "      <video:content_loc>" . htmlspecialchars($video['movieUrl'] ?? '') . "</video:content_loc>\n";
    echo "      <video:duration>300</video:duration>\n";
    echo "    </video:video>\n";
    
    echo "  </url>\n";
}

echo "</urlset>\n";
?>