<?php

namespace KupShop\ComponentsBundle\Twig\Components\Product\DeliveryTime;

use KupShop\ComponentsBundle\Attributes\Component;
use KupShop\ComponentsBundle\Attributes\Version;
use KupShop\ComponentsBundle\Twig\BaseComponent;
use KupShop\ComponentsBundle\Twig\DataProvider\ProductDataProvider;
use KupShop\ComponentsBundle\Twig\DataProvider\ProductDataTrait;
use KupShop\OrderingBundle\Util\Delivery\DeliveryDatesService;
use KupShop\OrderingBundle\Util\Order\DeliveryInfo;
use KupShop\OrderingBundle\Util\Purchase\PurchaseUtil;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

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

    public bool $show_in_store = true;

    private $productDeliveries;

    public function __construct(
        private DeliveryInfo $deliveryInfo,
        private PurchaseUtil $purchaseUtil,
        private DeliveryDatesService $deliveryDates,
        private readonly ProductDataProvider $productDataProvider,
    ) {
    }

    public function getText()
    {
        return $this->getProductUnified()->getDeliveryTimeText();
    }

    public function getIndex(): int
    {
        return $this->getProductUnified()->getDeliveryTime();
    }

    public function getPiecesInStore()
    {
        return $this->getProductUnified()->getInStore();
    }

    public function getMaxVisibleInStore()
    {
        $this->multiFetch()->fetchShowMaxInStore();

        return $this->getProductUnified()->getTotalAvailablePieces();
    }

    public function getUnitShortcut()
    {
        return $this->getProductUnified()->getUnit()['short_name'] ?? 'ks';
    }
}
