<?php

declare(strict_types=1);

namespace KupShop\AdminBundle\Admin\Actions;

class CopyProductVariationsAction extends AbstractAction implements IAction
{
    public function isEnabled()
    {
        return findModule(\Modules::PRODUCTS_VARIATIONS);
    }

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

    public function getName(): string
    {
        return 'Kopírovat varianty z produktu';
    }

    public function getHotKeys(): array
    {
        return [
            'key' => 'K',
            'modifier' => 'ALT+',
        ];
    }

    public function showInMassEdit()
    {
        return true;
    }

    public function execute(&$data, array $config, string $type): ActionResult
    {
        try {
            \Variations::duplicateVariations($config['id_product'], $this->getId());
        } catch (\Throwable $e) {
            return new ActionResult(false);
        }

        return new ActionResult(true);
    }
}
