<?php

declare(strict_types=1);

namespace KupShop\ComponentsBundle\GTM\Events;

use KupShop\ComponentsBundle\Interfaces\GTMComponentInterface;
use KupShop\GTMBundle\PageType\OtherPageType;
use KupShop\OrderingBundle\Entity\Purchase\ProductPurchaseItem;

class AddToCartClick extends OtherPageType implements GTMComponentInterface
{
    /**
     * @param \KupShop\ComponentsBundle\Twig\Components\Product\AddToCartButton|object $component
     */
    public function getPushData($component): object
    {
        $dataContainer = new \stdClass();
        $dataContainer->event = 'add_to_cart';
        $dataContainer->add = new \stdClass();
        $dataContainer->ecommerce = (object) [
            'items' => '@items',
            'quantity' => '@quantity',
        ];
        $dataContainer->add->item_list_name = '@item_list_name';
        $dataContainer->add->item_list_id = '@item_list_id';

        return $dataContainer;
    }

    public function getPushDataFromCartItem(ProductPurchaseItem $item): object
    {
        return $this->getPushData((object) []);
    }
}
