<?php
declare(strict_types=1);

require_once __DIR__ . '/includes/config.php';
require_once __DIR__ . '/includes/db.php';

header('Content-Type: application/xml; charset=utf-8');

$pdo = db();
$pages = [
    ['loc' => '',           'priority' => '1.0', 'changefreq' => 'weekly'],
    ['loc' => '/about.php',    'priority' => '0.8', 'changefreq' => 'monthly'],
    ['loc' => '/services.php', 'priority' => '0.9', 'changefreq' => 'weekly'],
    ['loc' => '/faq.php',      'priority' => '0.7', 'changefreq' => 'monthly'],
    ['loc' => '/blog.php',     'priority' => '0.6', 'changefreq' => 'weekly'],
    ['loc' => '/testimonials.php', 'priority' => '0.6', 'changefreq' => 'monthly'],
    ['loc' => '/contact.php',  'priority' => '0.7', 'changefreq' => 'monthly'],
];

$packages = $pdo->query("SELECT slug, updated_at FROM packages")->fetchAll();

echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xhtml="http://www.w3.org/1999/xhtml">
<?php foreach ($pages as $p): ?>
  <url>
    <loc><?= SITE_URL ?><?= e($p['loc']) ?></loc>
    <priority><?= $p['priority'] ?></priority>
    <changefreq><?= $p['changefreq'] ?></changefreq>
  </url>
<?php endforeach; ?>
<?php foreach ($packages as $pkg): ?>
  <url>
    <loc><?= SITE_URL ?>/package.php?slug=<?= e($pkg['slug']) ?></loc>
    <priority>0.8</priority>
    <changefreq>monthly</changefreq>
  </url>
<?php endforeach; ?>
</urlset>
