<?php

use External\PompoBundle\Util\ProductUtil;
use KupShop\CatalogBundle\ProductList\ProductCollection;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;

// TODO: delete me when review/pompo-ceny is merged
function smarty_function_get_product_deliverytime_info($params, &$smarty)
{
    if (empty($params['product'])) {
        throw new InvalidArgumentException('Missing required parameter \'product\'');
    }

    /** @var Product $product */
    $product = $params['product']->getProduct();

    $productUtil = ServiceContainer::getService(ProductUtil::class);
    $productUtil->fetchStoreInfo(
        new ProductCollection([$product->id => $product])
    );

    $result = [
        'inStoreMain' => $product->inStoreMain ?? 0,
        'inStoreSupplier' => $product->inStoreSupplier ?? 0,
        'inStoreSeller' => $product->inStoreSeller ?? 0,
        'inStoreSellerOther' => $product->inStoreSellerOther ?? 0,
    ];

    if (!empty($params['assign'])) {
        $smarty->assign($params['assign'], $result);
    } else {
        return $result;
    }
}
