<?php

declare(strict_types=1);

namespace KupShop\GTMBundle\Utils\Providers;

class ProductDataProvider
{
    private array $products = [];

    public function addProduct($product, $index = false)
    {
        $this->products[$index ?: $product->id] = $product;
    }

    public function addProducts(array $products)
    {
        foreach ($products as $product) {
            $this->products[$product->id] = $product;
        }
    }

    public function getProducts(): array
    {
        return $this->products;
    }

    public function clear()
    {
        $this->products = [];
    }
}
