<?php

namespace KupShop\ElninoBundle\GTM\DataLoaders;

use KupShop\FeedGeneratorBundle\Utils\Map;
use KupShop\KupShopBundle\Views\View;

class Products extends \KupShop\GTMBundle\Utils\DataLoaders\Products
{
    protected Map $map;

    public function getData($product, ?View $view = null)
    {
        $p = parent::getData($product, $view);

        if ($view) {
            $templateData = $view->getTemplateData();

            $p->sex = $this->map->map('pohlaví', $templateData['body']['serie']['sex']);
            $p->cosmetics = $templateData['body']['model']['cosmetics'] ?? null;
            $p->model_name = $templateData['body']['model']['short_title'] ?? null;
        }

        return $p;
    }

    /**
     * @required
     */
    public function setMap(Map $map): void
    {
        $this->map = $map;
    }
}
