<?php

declare(strict_types=1);

namespace KupShop\GraphQLBundle\ApiShared\Types\Product\MultiSet;

use KupShop\CatalogBundle\ProductList\ProductCollection;
use KupShop\GraphQLBundle\ApiShared\Types\Price\Price;
use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Type;

#[Type]
class MultiSet
{
    public function __construct(private array $multiSet, public ProductCollection $collection)
    {
    }

    #[Field]
    public function getProductId(): int
    {
        return $this->multiSet['id'];
    }

    #[Field]
    public function getPriceFrom(): Price
    {
        return new Price($this->multiSet['priceFrom']);
    }

    /**
     * @return MultiSetCategory[]
     */
    #[Field]
    public function getCategories(): array
    {
        $categories = [];
        foreach ($this->multiSet['categories'] as $key => $category) {
            $categories[$key] = new MultiSetCategory($category, $this->collection);
        }

        return $categories;
    }

    #[Field]
    public function getInStore(): int
    {
        return (int) $this->multiSet['inStore'];
    }
}
