<?php


namespace AutoAdmin\Bundle\Seo\Controller;


use AutoAdmin\Bundle\Content\Site\SiteContextHelper;
use AutoAdmin\Bundle\Seo\Cache\SitemapCacheHandler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class SitemapController
{
    public function __construct(
        protected SitemapCacheHandler $cacheHandler,
        protected SiteContextHelper $contextHelper,
    ) {
    }

    public function index(Request $request): Response
    {
        $section = $request->get('section', 'default');

        $sitemaps = $this->cacheHandler->getValue();

        $sectionSitemap = $sitemaps[$section];

        return new Response($sectionSitemap, 200, ['content-type' => 'text/xml;charset=UTF-8']);
    }
}