<?php

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Bridge\Symfony\Bundle\Context;

use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

final readonly class ShopCountryContext
{
    public function __construct(private RequestStack $requestStack) {}

    public function isBlocked(): bool
    {
        return true === $this->getSession()?->get('blockShop');
    }

    public function getCountryCode(): ?string
    {
        $countryCode = $this->getSession()?->get('blockShopCountry');

        return \is_string($countryCode) && '' !== $countryCode ? $countryCode : null;
    }

    private function getSession(): ?SessionInterface
    {
        $request = $this->requestStack->getCurrentRequest();

        return $request?->hasSession() ? $request->getSession() : null;
    }
}
