<?php

declare(strict_types=1);

namespace KupShop\DynamicRelatedProductsBundle\Admin\Actions;

use KupShop\AdminBundle\Admin\Actions\AbstractAction;
use KupShop\AdminBundle\Admin\Actions\ActionResult;
use KupShop\AdminBundle\Admin\Actions\IAction;
use KupShop\DynamicRelatedProductsBundle\Utils\DynamicRelatedProductsService;
use Symfony\Contracts\Service\Attribute\Required;

class RefreshDataAction extends AbstractAction implements IAction
{
    #[Required]
    public DynamicRelatedProductsService $relatedProductsService;

    public function getTypes(): array
    {
        return ['DynamicRelatedProducts'];
    }

    public function getIcon(): string
    {
        return 'glyphicon glyphicon-refresh';
    }

    public function showInMassEdit(): bool
    {
        return true;
    }

    public function getName(): string
    {
        return 'Aktualizovat data';
    }

    public function execute(&$data, array $config, string $type): ActionResult
    {
        $this->relatedProductsService->updateDynamicRelatedProductsById((int) $this->getId());

        return new ActionResult(true);
    }
}
