<?php

namespace KupShop\ComponentsBundle\Twig\Components\Product;

use KupShop\ComponentsBundle\Attributes\Component;
use KupShop\ComponentsBundle\Attributes\Version;
use KupShop\ComponentsBundle\Entity\Thumbnail;
use KupShop\ComponentsBundle\Twig\BaseComponent;
use KupShop\ComponentsBundle\Twig\DataProvider\ProductDataTrait;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

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

    public function getTitle(): string
    {
        return $this->product->title;
    }

    public function getProductCode(): string
    {
        return $this->product->code;
    }

    public function getThumbnail(): ?Thumbnail
    {
        $this->multiFetch()->fetchProductsPhotoIds();

        if ($this->product->photoId > 0) {
            return new Thumbnail((string) $this->product->photoId, $this->product->photoDescr, $this->product->photoDateUpdate);
        }

        return null;
    }
}
