<?php
declare(strict_types=1);

namespace Autogedal\EanTools\Controller\Adminhtml;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\View\Result\Page;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\View\Result\PageFactory;

abstract class AbstractTool extends Action
{
    public const ADMIN_RESOURCE = 'Autogedal_EanTools::ean_tools';

    public function __construct(
        Context $context,
        private readonly PageFactory $resultPageFactory
    ) {
        parent::__construct($context);
    }

    protected function buildPage(string $title): Page
    {
        $page = $this->resultPageFactory->create();
        $page->setActiveMenu(self::ADMIN_RESOURCE);

        $pageTitle = $page->getConfig()->getTitle();
        $pageTitle->prepend(__('EAN Tools'));
        $pageTitle->prepend($title);

        return $page;
    }

    protected function redirectTo(string $path, array $params = []): Redirect
    {
        return $this->resultRedirectFactory->create()->setPath($path, $params);
    }
}
