<?php

declare(strict_types=1);

namespace KupShop\GraphQLBundle\ApiAdmin\Controller\Catalog;

use KupShop\GraphQLBundle\ApiAdmin\Annotation\Module;
use KupShop\GraphQLBundle\ApiAdmin\Types\Catalog\Producer\Input\ProducerInput;
use KupShop\GraphQLBundle\ApiAdmin\Types\Catalog\Producer\Response\ProducerMutateResponse;
use KupShop\GraphQLBundle\ApiAdmin\Types\Collection\ProducerCollection;
use KupShop\GraphQLBundle\ApiAdmin\Util\Catalog\ProducerUtil;
use KupShop\GraphQLBundle\ApiShared\Types\Product\Producer;
use TheCodingMachine\GraphQLite\Annotations\Mutation;
use TheCodingMachine\GraphQLite\Annotations\Query;

class ProducerController
{
    private ProducerUtil $producerUtil;

    public function __construct(ProducerUtil $producerUtil)
    {
        $this->producerUtil = $producerUtil;
    }

    /**
     * Výrobce podle ID.
     *
     * @Query()
     *
     * @Module("PRODUCERS")
     */
    public function producer(int $id): ?Producer
    {
        return $this->producerUtil->getProducer($id);
    }

    /**
     * Seznam výrobců.
     *
     * @Query()
     *
     * @Module("PRODUCERS")
     */
    public function producers(): ProducerCollection
    {
        return $this->producerUtil->getProducers();
    }

    /**
     * Vytvoří / aktualizuje výrobce.
     */
    #[Mutation]
    #[Module(\Modules::PRODUCERS)]
    public function producerCreateOrUpdate(ProducerInput $input): ProducerMutateResponse
    {
        return $this->producerUtil->createOrUpdateProducer($input);
    }
}
