<?php
require_once 'config/site_config.php';
header('Content-Type: application/xml; charset=UTF-8');
header('X-Robots-Tag: noindex'); // sitemap itself should not be indexed
header('Cache-Control: public, max-age=3600');

$today = date('Y-m-d');
$month = date('Y-m-d', strtotime('-30 days'));

$urls = [
    // Core pages
    ['loc' => SITE_URL . '/',                                    'lastmod' => $today, 'changefreq' => 'weekly',  'priority' => '1.0'],
    ['loc' => SITE_URL . '/features',                            'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.9'],
    ['loc' => SITE_URL . '/pricing',                             'lastmod' => $today, 'changefreq' => 'weekly',  'priority' => '0.9'],
    ['loc' => SITE_URL . '/how-it-works',                        'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.8'],
    ['loc' => SITE_URL . '/testimonials',                        'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.7'],
    ['loc' => SITE_URL . '/blog',                                'lastmod' => $today, 'changefreq' => 'weekly',  'priority' => '0.8'],

    // Industry pages
    ['loc' => SITE_URL . '/free/retail-billing-software',        'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.8'],
    ['loc' => SITE_URL . '/free/kirana-store-billing-software',  'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.8'],
    ['loc' => SITE_URL . '/free/distributor-billing-software',   'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.8'],
    ['loc' => SITE_URL . '/free/medical-shop-billing-software',  'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.8'],
    ['loc' => SITE_URL . '/free/cloth-shop-billing-software',    'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.8'],

    // Blog articles
    ['loc' => SITE_URL . '/blog/gst-billing-software-kya-hai',  'lastmod' => '2025-01-15', 'changefreq' => 'yearly', 'priority' => '0.7'],
    ['loc' => SITE_URL . '/blog/gstr-1-kaise-bhare',            'lastmod' => '2025-01-20', 'changefreq' => 'yearly', 'priority' => '0.7'],
    ['loc' => SITE_URL . '/blog/inventory-management-kaise-kare','lastmod' => '2025-01-25', 'changefreq' => 'yearly', 'priority' => '0.7'],
    ['loc' => SITE_URL . '/blog/gst-invoice-kaise-banaye',      'lastmod' => '2025-02-01', 'changefreq' => 'yearly', 'priority' => '0.7'],
    ['loc' => SITE_URL . '/blog/billing-software-vs-tally',     'lastmod' => '2025-02-10', 'changefreq' => 'yearly', 'priority' => '0.7'],
    ['loc' => SITE_URL . '/blog/udhar-ka-hisaab-kaise-rakhe',   'lastmod' => '2025-02-15', 'changefreq' => 'yearly', 'priority' => '0.7'],
    ['loc' => SITE_URL . '/blog/gst-billing-kaise-kare',        'lastmod' => '2025-03-01', 'changefreq' => 'yearly', 'priority' => '0.7'],
    ['loc' => SITE_URL . '/blog/best-billing-software-india',   'lastmod' => '2025-03-10', 'changefreq' => 'yearly', 'priority' => '0.7'],
    ['loc' => SITE_URL . '/blog/inventory-management-tips',     'lastmod' => '2025-03-20', 'changefreq' => 'yearly', 'priority' => '0.7'],

    // Free tools
    ['loc' => SITE_URL . '/tools/free-gst-calculator',              'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.7'],
    ['loc' => SITE_URL . '/tools/free-invoice-generator',           'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.7'],
    ['loc' => SITE_URL . '/tools/free-quotation-maker',             'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.7'],
    ['loc' => SITE_URL . '/tools/free-proforma-invoice-generator',  'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.6'],
    ['loc' => SITE_URL . '/tools/free-purchase-order-generator',    'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.6'],
    ['loc' => SITE_URL . '/tools/free-receipt-maker',               'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.6'],
    ['loc' => SITE_URL . '/tools/free-qr-code-generator',           'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.6'],
    ['loc' => SITE_URL . '/tools/free-barcode-generator',           'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.6'],

    // Formats
    ['loc' => SITE_URL . '/formats/invoice-format',            'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.6'],
    ['loc' => SITE_URL . '/formats/quotation-format',          'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.6'],
    ['loc' => SITE_URL . '/formats/balance-sheet-format',      'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.6'],
    ['loc' => SITE_URL . '/formats/bill-book-format',          'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.6'],
    ['loc' => SITE_URL . '/formats/receipt-format',            'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.6'],
    ['loc' => SITE_URL . '/formats/credit-note-format',        'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.6'],
    ['loc' => SITE_URL . '/formats/debit-note-format',         'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.6'],
    ['loc' => SITE_URL . '/formats/delivery-challan-format',   'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.6'],
    ['loc' => SITE_URL . '/formats/estimate-format',           'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.6'],
    ['loc' => SITE_URL . '/formats/sales-report-format',       'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.6'],
    ['loc' => SITE_URL . '/formats/work-order-format',         'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.6'],
    ['loc' => SITE_URL . '/formats/income-statement-format',   'lastmod' => $month, 'changefreq' => 'monthly', 'priority' => '0.6'],

    // Legal pages
    ['loc' => SITE_URL . '/privacy',  'lastmod' => $month, 'changefreq' => 'yearly', 'priority' => '0.4'],
    ['loc' => SITE_URL . '/terms',    'lastmod' => $month, 'changefreq' => 'yearly', 'priority' => '0.4'],
    ['loc' => SITE_URL . '/refund',   'lastmod' => $month, 'changefreq' => 'yearly', 'priority' => '0.4'],
];

echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' . "\n";
echo '        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . "\n";
echo '        xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9' . "\n";
echo '        http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . "\n";

foreach ($urls as $url) {
    echo "  <url>\n";
    echo "    <loc>" . htmlspecialchars($url['loc']) . "</loc>\n";
    echo "    <lastmod>" . $url['lastmod'] . "</lastmod>\n";
    echo "    <changefreq>" . $url['changefreq'] . "</changefreq>\n";
    echo "    <priority>" . $url['priority'] . "</priority>\n";
    echo "  </url>\n";
}

echo '</urlset>';
