<?php

declare(strict_types=1);

namespace KupShop\ComponentsBundle\GTM\PageViews;

use KupShop\ComponentsBundle\GTM\Utils\DataLoaders\Products;
use KupShop\ComponentsBundle\Interfaces\GTMComponentViewInterface;
use KupShop\ComponentsBundle\Twig\BaseComponent;
use KupShop\ComponentsBundle\Twig\DataProvider\ProductDataProvider;
use Symfony\Contracts\Service\Attribute\Required;

class Product implements GTMComponentViewInterface
{
    #[Required]
    public ProductDataProvider $productDataProvider;

    #[Required]
    public Products $productLoader;

    /**
     * @param \KupShop\ComponentsBundle\Twig\Components\Product\View $component
     */
    public function getPushData($component): object
    {
        return (object) [
            'ecommerce' => (object) [
                'items' => $this->productLoader->getProducts([$component->getProductUnified()], null, true),
            ],
        ];
    }

    public function getPageTypeString(BaseComponent $component): ?string
    {
        return 'product';
    }
}
