<?php

namespace KupShop\PohodaBundle\Utils\Tools;

use KupShop\CatalogBundle\Util\Product\ProductExporter;
use Symfony\Contracts\Service\Attribute\Required;

class PohodaProductExporter extends ProductExporter
{
    #[Required]
    public VatHelper $vatHelper;

    protected $parameters = [
        'variationsProcess' => true,
        'photoProcess' => false,
        'sectionProcess' => false,
        'parametersProcess' => false,
        'relatedProcess' => false,
        'collectionsProcess' => false,
    ];

    protected $variationIDs = [];

    /**
     * @param \Product $product
     */
    protected function fetchVariations($product)
    {
        $variations = parent::fetchVariations($product);
        foreach ($variations['variations'] as $variation) {
            if (!array_key_exists($variation['id'], $this->variationIDs)) {
                unset($variations['variations'][$variation['id']]);
            }
        }

        return $variations;
    }

    public function setVariationIDs($variationIDs)
    {
        $this->variationIDs = $variationIDs;
    }

    protected function modifyProductElement(\SimpleXMLElement $element, \Product $product): void
    {
        $element->RATEVAT = $this->vatHelper->loadRateVatFromCache($product['vat']);
    }

    protected function modifyVariationElement(\SimpleXMLElement $element, $variation, \Product $product): void
    {
        $element->RATEVAT = $this->vatHelper->loadRateVatFromCache($product['vat']);
    }
}
