<?php

namespace KupShop\SellerBundle\Twig\Components;

use KupShop\ComponentsBundle\Attributes\Component;
use KupShop\ComponentsBundle\Attributes\Version;
use KupShop\ComponentsBundle\Twig\BaseComponent;
use KupShop\ComponentsBundle\Twig\DataProvider\ProductDataTrait;
use KupShop\StoresBundle\Utils\StoresInStore;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

#[AsTwigComponent(template: '@Seller/components/SellerAvailability/SellerAvailability.1.html.twig')]
#[Component(1, [
    new Version(1, newJs: null),
])]
class SellerAvailability extends BaseComponent
{
    use ProductDataTrait;

    public function __construct(private StoresInStore $inStoreService)
    {
    }

    public function getNumberOfAvailableSellers()
    {
        $productInStores = $this->inStoreService->getProductInStores($this->id_product, $this->id_variation);
        $numberOfAvailableSellers = 0;

        foreach ($productInStores as $sellerAvailability) {
            if (intval($sellerAvailability) > 0) {
                $numberOfAvailableSellers++;
            }
        }

        return $numberOfAvailableSellers;
    }
}
