<?php

declare(strict_types=1);

namespace KupShop\GraphQLBundle\ApiAdmin\Controller\Catalog;

use KupShop\GraphQLBundle\ApiAdmin\Annotation\Module;
use KupShop\GraphQLBundle\ApiAdmin\Types\Catalog\Product\Input\ProductUnitInput;
use KupShop\GraphQLBundle\ApiAdmin\Types\Catalog\Product\Response\ProductUnitMutateResponse;
use KupShop\GraphQLBundle\ApiAdmin\Types\Collection\ProductUnitCollection;
use KupShop\GraphQLBundle\ApiAdmin\Util\Catalog\ProductUnitUtil;
use KupShop\GraphQLBundle\ApiShared\Types\Product\ProductUnit;
use TheCodingMachine\GraphQLite\Annotations\Mutation;
use TheCodingMachine\GraphQLite\Annotations\Query;

class ProductUnitController
{
    public function __construct(
        private readonly ProductUnitUtil $productUnitUtil,
    ) {
    }

    /**
     * Měrná jednotka.
     */
    #[Query]
    #[Module(\Modules::PRODUCTS, \Modules::SUB_UNITS)]
    public function productUnit(int $id): ?ProductUnit
    {
        return $this->productUnitUtil->getProductUnit($id);
    }

    /**
     * Seznam měrných jednotek.
     */
    #[Query]
    #[Module(\Modules::PRODUCTS, \Modules::SUB_UNITS)]
    public function productUnits(): ProductUnitCollection
    {
        return $this->productUnitUtil->getProductUnits();
    }

    /**
     * Vytvoří/aktualizuje měrnou jednotku.
     */
    #[Mutation]
    #[Module(\Modules::PRODUCTS, \Modules::SUB_UNITS)]
    public function productUnitCreateOrUpdate(ProductUnitInput $input): ProductUnitMutateResponse
    {
        return $this->productUnitUtil->createOrUpdateProductUnit($input);
    }
}
