<?php

namespace KupShop\GraphQLBundle\ApiPos\Types\Product;

use KupShop\GraphQLBundle\ApiPos\Types\Warehouse\PosStoreItemCollection;
use KupShop\GraphQLBundle\ApiPos\Types\Warehouse\PosWarehouseCollection;
use KupShop\GraphQLBundle\ApiShared\Types\Price\Price;
use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Type;

#[Type]
class PosVariationInfoItem
{
    public function __construct(
        protected array $variation,
        protected int $inStock,
        protected ?PosStoreItemCollection $stores = null,
        protected ?PosWarehouseCollection $warehouse = null)
    {
    }

    #[Field(description: 'ID varianty')]
    public function getId(): int
    {
        return $this->variation['id'];
    }

    #[Field(description: 'EAN')]
    public function getEan(): ?string
    {
        return "{$this->variation['ean']}";
    }

    #[Field(description: 'Kód')]
    public function getCode(): ?string
    {
        return $this->variation['code'];
    }

    #[Field(description: 'Cena')]
    public function getPrice(): Price
    {
        return new Price($this->variation['price']->getObject());
    }

    #[Field(description: 'Skladovost pro pokladnu')]
    public function getPosInStore(): int
    {
        return $this->inStock ?? 0;
    }

    #[Field(description: 'Skladovost varianty')]
    public function getInStore(): int
    {
        return $this->variation['in_store'] ?? 0;
    }

    #[Field(description: 'Název varianty')]
    public function getTitle(): string
    {
        return $this->variation['title'] ?? '';
    }

    #[Field(description: 'Cesta obrázku')]
    public function getPhoto(): ?string
    {
        return $this->variation['image']['src'] ?? null;
    }

    #[Field(description: 'Sklady')]
    public function getStores(): ?PosStoreItemCollection
    {
        return $this->stores;
    }

    #[Field(description: 'Pozice')]
    public function getWarehouse(): ?PosWarehouseCollection
    {
        return $this->warehouse;
    }
}
