<?php

declare(strict_types=1);

namespace External\LeaflyBundle\View;

use KupShop\KupShopBundle\Context\UserContext;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class PageView extends \KupShop\ContentBundle\View\PageView
{
    /** @var UserContext */
    private $userContext;

    /**
     * @required
     */
    public function setUserContext(UserContext $userContext): void
    {
        $this->userContext = $userContext;
    }

    public function getBodyVariables()
    {
        $vars = parent::getBodyVariables();

        if (!empty($this->getPage()->getData()['b2b_page']) && $this->getPage()->getData()['b2b_page'] == 'Y' && !$this->userContext->isDealer()) {
            throw new NotFoundHttpException('User not B2B');
        }

        return $vars;
    }
}
