<?php

declare(strict_types=1);

namespace KupShop\GraphQLBundle\Register;

use KupShop\GraphQLBundle\Contracts\AbstractDataType;
use KupShop\GraphQLBundle\Mapper\DataTypeMapperFactory;
use KupShop\GraphQLBundle\Middleware\ModuleFieldMiddleware;
use KupShop\GraphQLBundle\Middleware\ModuleInputFieldMiddleware;
use KupShop\GraphQLBundle\Util\SchemaFactory;
use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
use Symfony\Component\DependencyInjection\ServiceLocator;

class GraphQLRegister extends AbstractGraphQLRegister
{
    public function __construct(
        #[TaggedLocator(tag: AbstractDataType::SERVICE_TAG)]
        private ServiceLocator $dataTypeLocator,
    ) {
    }

    public function getControllerNamespaces(): iterable
    {
        yield SchemaFactory::TYPE_ADMIN => [
            'KupShop\\GraphQLBundle\\ApiAdmin\\Controller\\',
        ];

        yield SchemaFactory::TYPE_POS => [
            'KupShop\\GraphQLBundle\\ApiPos\\Controller\\',
        ];
    }

    public function getTypeNamespaces(): iterable
    {
        yield SchemaFactory::TYPE_ADMIN => [
            'KupShop\\GraphQLBundle\\ApiShared\\Types\\',
            'KupShop\\GraphQLBundle\\ApiAdmin\\Types\\',
        ];

        yield SchemaFactory::TYPE_POS => [
            'KupShop\\GraphQLBundle\\ApiShared\\Types\\',
            'KupShop\\GraphQLBundle\\ApiAdmin\\Types\\',
            'KupShop\\GraphQLBundle\\ApiPos\\Types\\',
        ];
    }

    public function getFieldMiddlewares(): iterable
    {
        yield SchemaFactory::TYPE_ADMIN => [
            new ModuleFieldMiddleware(),
        ];
    }

    public function getInputFieldMiddlewares(): iterable
    {
        yield SchemaFactory::TYPE_ADMIN => [
            new ModuleInputFieldMiddleware(),
        ];
    }

    public function getTypeMapperFactories(): iterable
    {
        yield SchemaFactory::TYPE_POS => [
            new DataTypeMapperFactory($this->dataTypeLocator),
        ];

        yield SchemaFactory::TYPE_ADMIN => [
            new DataTypeMapperFactory($this->dataTypeLocator),
        ];
    }
}
