<?php
/**
 * AppVeloce — Sitemap XML dinamica
 * URL: /sitemap.xml  (redirect via .htaccess oppure rinomina in sitemap.php e punta robots.txt)
 */
declare(strict_types=1);
require_once __DIR__ . '/config/config.php';

header('Content-Type: application/xml; charset=utf-8');
header('X-Robots-Tag: noindex');

$base = rtrim(SITE_URL, '/');
$now  = date('Y-m-d');

$pages = [
    /* Homepage */
    ['loc' => '/',                   'priority' => '1.0', 'freq' => 'weekly',  'lastmod' => $now],
    /* Servizi principali */
    ['loc' => '/servizi.php',        'priority' => '0.9', 'freq' => 'weekly',  'lastmod' => $now],
    ['loc' => '/preventivo.php',     'priority' => '0.9', 'freq' => 'monthly', 'lastmod' => $now],
    ['loc' => '/come-funziona.php',  'priority' => '0.8', 'freq' => 'monthly', 'lastmod' => $now],
    ['loc' => '/portfolio.php',      'priority' => '0.7', 'freq' => 'monthly', 'lastmod' => $now],
    ['loc' => '/faq.php',            'priority' => '0.7', 'freq' => 'monthly', 'lastmod' => $now],
    ['loc' => '/contatti.php',       'priority' => '0.7', 'freq' => 'monthly', 'lastmod' => $now],
    /* Legal */
    ['loc' => '/privacy.php',        'priority' => '0.3', 'freq' => 'yearly',  'lastmod' => $now],
    ['loc' => '/cookie.php',         'priority' => '0.3', 'freq' => 'yearly',  'lastmod' => $now],
    ['loc' => '/termini.php',        'priority' => '0.3', 'freq' => 'yearly',  'lastmod' => $now],
    /* Blog index */
    ['loc' => '/blog/',              'priority' => '0.8', 'freq' => 'weekly',  'lastmod' => $now],
    /* Blog articles */
    ['loc' => '/blog/cos-e-vibe-coding.php',                 'priority' => '0.8', 'freq' => 'monthly', 'lastmod' => $now],
    ['loc' => '/blog/quanto-costa-app.php',                  'priority' => '0.8', 'freq' => 'monthly', 'lastmod' => $now],
    ['loc' => '/blog/stufo-token-claude-ai.php',             'priority' => '0.8', 'freq' => 'monthly', 'lastmod' => $now],
    ['loc' => '/blog/gestione-inventario-barcode.php',       'priority' => '0.8', 'freq' => 'monthly', 'lastmod' => $now],
    ['loc' => '/blog/cassa-automatica-barcode.php',          'priority' => '0.7', 'freq' => 'monthly', 'lastmod' => $now],
    ['loc' => '/blog/revisione-codice-vulnerabilita-ai.php', 'priority' => '0.7', 'freq' => 'monthly', 'lastmod' => $now],
    ['loc' => '/blog/app-prenotazioni-ristorante.php',       'priority' => '0.7', 'freq' => 'monthly', 'lastmod' => $now],
];

/* Città */
$cities = [
    'milano','roma','napoli','torino','bologna','firenze','bari','palermo',
    'bergamo','brescia','genova','venezia','verona','padova','modena','parma',
    'reggio-emilia','perugia','trento','crema','cremona',
];
foreach ($cities as $c) {
    $pages[] = ['loc' => '/citta/' . $c, 'priority' => '0.7', 'freq' => 'monthly', 'lastmod' => $now];
}

echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
        http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . "\n";

foreach ($pages as $p) {
    echo "  <url>\n";
    echo "    <loc>{$base}{$p['loc']}</loc>\n";
    echo "    <lastmod>{$p['lastmod']}</lastmod>\n";
    echo "    <changefreq>{$p['freq']}</changefreq>\n";
    echo "    <priority>{$p['priority']}</priority>\n";
    echo "  </url>\n";
}

echo '</urlset>';
