<?php
declare(strict_types=1);

namespace Autogedal\Labels\Block\Adminhtml\Label\Edit;

use Autogedal\Labels\Model\LabelFactory;
use Magento\Backend\Block\Widget\Context;

class GenericButton
{
    /**
     * @var Context
     */
    protected $context;

    /**
     * @var LabelFactory
     */
    protected $labelFactory;

    public function __construct(
        Context $context,
        LabelFactory $labelFactory
    ) {
        $this->context = $context;
        $this->labelFactory = $labelFactory;
    }

    public function getLabelId(): ?int
    {
        $id = (int)$this->context->getRequest()->getParam('label_id');
        if ($id) {
            $model = $this->labelFactory->create()->load($id);
            if ($model->getId()) {
                return (int)$model->getId();
            }
        }

        return null;
    }

    public function getUrl(string $route = '', array $params = []): string
    {
        return $this->context->getUrlBuilder()->getUrl($route, $params);
    }
}

