<?php


namespace AutoAdmin\Bundle\Content\Profiler;


use AutoAdmin\Bundle\Content\Site\SiteContextHelper;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Throwable;

class SiteContextCollector extends DataCollector
{

    public function __construct(
        private SiteContextHelper $contextHelper
    ) {
    }

    public function collect(Request $request, Response $response, Throwable $exception = null)
    {
        $this->data = [
            'site' => $site = $this->contextHelper->getSite(),
            'locale' => $locale = $this->contextHelper->getLocale(),
            'domain' => $this->contextHelper->getDomainByLocale($site, $locale),
        ];
    }

    public function getSite()
    {
        return $this->data['site'];
    }

    public function getDomain()
    {
        return $this->data['domain'];
    }

    public function getLocale()
    {
        return $this->data['locale'];
    }

    public function reset()
    {
        $this->data = [];
    }

    public function getName(): string
    {
        return 'aa_content.site_context_collector';
    }

}
