<?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): void
    {
        $site = $this->contextHelper->getSite();
        $locale = $this->contextHelper->getLocale();

        if ($site === null || $locale === null) {
            return;
        }

        $this->data = [
            'site' => $site,
            'locale' => $locale,
            '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(): void
    {
        $this->data = [];
    }

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