<?php

declare(strict_types=1);

namespace KupShop\AgeVerifyBundle\View;

use KupShop\AgeVerifyBundle\Utils\AdultoUtil;
use KupShop\KupShopBundle\Context\UserContext;
use KupShop\KupShopBundle\Util\Contexts;
use KupShop\KupShopBundle\Views\View;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Service\Attribute\Required;

class AdultoView extends View
{
    protected $template = 'ageverify/adulto.tpl';
    protected $title = 'Ověření pomocí Adulto';

    #[Required]
    public RequestStack $requestStack;

    #[Required]
    public AdultoUtil $adultoUtil;

    public function getBreadcrumbs(): ?array
    {
        return getReturnNavigation(-1, 'USER', [$this->getTitle()]);
    }

    public function getBodyVariables(): array
    {
        $vars = parent::getBodyVariables();
        $vars['adulto_public_key'] = \Settings::getDefault()['age_verify']['adulto']['public_key'] ?? '';
        $vars['user'] = Contexts::get(UserContext::class)->getActive();

        return $vars;
    }

    public function submitForm(): array
    {
        $mainRequest = $this->requestStack->getMainRequest();

        return $this->adultoUtil->checkAdultoUid($mainRequest->get('adultocz-uid') ?? '');
    }
}
