<?php

namespace AutoAdmin\Bundle\Seo\Sitemap;

use Thepixeldeveloper\Sitemap\Drivers\XmlWriterDriver;

class SitemapRenderer
{
    private SitemapManager $manager;

    public function __construct(SitemapManager $manager)
    {
        $this->manager = $manager;
    }

    public function render($hostAndScheme, string $section = 'default'): ?string
    {
        $urlSets = $this->manager->build($hostAndScheme, $section);

        if (!isset($urlSets[$section])) {
            return null;
        }

        $urlset = $urlSets[$section];
        $driver = new XmlWriterDriver();
        $urlset->accept($driver);

        return $driver->output();
    }

    public function getSections(): array
    {
        return $this->manager->getSections();
    }
}
