<?php

declare(strict_types=1);

namespace KupShop\GraphQLBundle\ApiAdmin\Controller;

use KupShop\GraphQLBundle\ApiAdmin\Annotation\Module;
use KupShop\GraphQLBundle\ApiAdmin\Types\Parameters;
use KupShop\GraphQLBundle\ApiAdmin\Types\Return\Input\ReturnCreateInput;
use KupShop\GraphQLBundle\ApiAdmin\Types\Return\Input\ReturnFilterInput;
use KupShop\GraphQLBundle\ApiAdmin\Types\Return\Input\ReturnUpdateInput;
use KupShop\GraphQLBundle\ApiAdmin\Types\Return\Response\ReturnMutateResponse;
use KupShop\GraphQLBundle\ApiAdmin\Types\Return\ReturnCollection;
use KupShop\GraphQLBundle\ApiAdmin\Types\Return\ReturnDto;
use KupShop\GraphQLBundle\ApiAdmin\Util\ReturnUtil;
use TheCodingMachine\GraphQLite\Annotations\Mutation;
use TheCodingMachine\GraphQLite\Annotations\Query;
use TheCodingMachine\GraphQLite\Annotations\UseInputType;

class ReturnController
{
    public function __construct(
        private readonly ?ReturnUtil $returnUtil,
    ) {
    }

    /**
     * Načte vratku podle ID.
     */
    #[Query]
    #[Module(\Modules::RETURNS)]
    public function return(int $id): ?ReturnDto
    {
        return $this->returnUtil->getReturn($id);
    }

    /**
     * Načte seznam vratek.
     */
    #[Query]
    #[Module(\Modules::RETURNS)]
    public function returns(
        int $offset = 0,
        int $limit = 100,
        #[UseInputType('ReturnSortInput')] ?Parameters $sort = null,
        ?ReturnFilterInput $filter = null,
    ): ReturnCollection {
        return $this->returnUtil->getReturns($offset, $limit, $sort, $filter);
    }

    /**
     * Vytvoří vratku.
     */
    #[Mutation]
    public function returnCreate(ReturnCreateInput $input): ReturnMutateResponse
    {
        return $this->returnUtil->createReturn($input);
    }

    /**
     * Aktualizace vratky.
     */
    #[Mutation]
    public function returnUpdate(ReturnUpdateInput $input): ReturnMutateResponse
    {
        return $this->returnUtil->updateReturn($input);
    }
}
