<?php

declare(strict_types=1);

namespace KupShop\GraphQLBundle\ApiAdmin\Controller;

use KupShop\GraphQLBundle\ApiAdmin\Annotation\Module;
use KupShop\GraphQLBundle\ApiAdmin\Types\Seller\Input\SellerInput;
use KupShop\GraphQLBundle\ApiAdmin\Types\Seller\Response\SellerMutateResponse;
use KupShop\GraphQLBundle\ApiAdmin\Util\SellerUtil;
use KupShop\GraphQLBundle\ApiShared\Types\Seller\Seller;
use KupShop\GraphQLBundle\ApiShared\Types\Seller\SellerCollection;
use TheCodingMachine\GraphQLite\Annotations\Mutation;
use TheCodingMachine\GraphQLite\Annotations\Query;

class SellerController
{
    private SellerUtil $sellerUtil;

    public function __construct(SellerUtil $sellerUtil)
    {
        $this->sellerUtil = $sellerUtil;
    }

    /**
     * Seznam prodejen.
     */
    #[Query]
    #[Module(\Modules::SELLERS)]
    // using $limit = 1000 as default because of backward compatibility when there was no offset and limit parameter
    public function sellers(int $offset = 0, int $limit = 1000): SellerCollection
    {
        return $this->sellerUtil->getSellers($offset, $limit);
    }

    /**
     * Načte prodejnu podle ID.
     */
    #[Query]
    #[Module(\Modules::SELLERS)]
    public function seller(int $id): ?Seller
    {
        return $this->sellerUtil->getSeller($id);
    }

    /**
     * Vytvoření / aktualizace prodejny.
     */
    #[Mutation]
    #[Module(\Modules::SELLERS)]
    public function sellerCreateOrUpdate(SellerInput $input): SellerMutateResponse
    {
        return $this->sellerUtil->createOrUpdateSeller($input);
    }
}
