# config/services.yaml
imports:
    - { resource: opentalent/* }
    - { resource: services/* }

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
        bind:
            $opentalentConfig: '%kernel.project_dir%%env(OPENTALENT_CONFIG)%'
            $internalFilesUploadUri: '%env(INTERNAL_FILES_DOWNLOAD_URI)%'
            $internalRequestsToken: '%env(INTERNAL_REQUESTS_TOKEN)%'
            $bindfileBufferFile: '%env(BIND_FILE_BUFFER_FILE)%'
            $persistProcessor: '@api_platform.doctrine.orm.state.persist_processor'
            $removeProcessor: '@api_platform.doctrine.orm.state.remove_processor'
            $opentalentNoReplyEmailAddress: 'noreply@opentalent.fr'
            $legacyBaseUrl: '%env(PUBLIC_API_LEG_BASE_URL)%'
            $baseUrl: '%env(PUBLIC_API_BASE_URL)%'

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App\:
        resource: '../src/*'
        exclude:
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.php'
            - '../src/Tests/'

    App\OpenApi\OpenApiFactory:
        decorates: 'api_platform.openapi.factory'
        arguments: [ '@App\OpenApi\OpenApiFactory.inner' ]
        autoconfigure: false

    App\Service\Cotisation\Utils:
        public: true

    App\Service\Education\Utils:
        public: true

    App\Service\Network\Utils:
        public: true

    App\Service\Organization\Utils:
        public: true

    Gaufrette\Filesystem: '@knp_gaufrette.filesystem_map'

    # To use the test fixtures
    App\Tests\Fixture\:
        resource: '%kernel.project_dir%/tests/Fixture/*'

    #########################################
    ##  TAG Services ##
    _instanceof:
        App\Doctrine\Access\AdditionalExtension\AdditionalAccessExtensionInterface:
            tags: ['app.extensions.access']
        App\Service\Access\OptionalsRolesInterface:
            tags: ['app.optionalsroles']
        App\Service\Export\ExporterInterface:
            tags: ['app.exporter']
        App\Service\Export\Encoder\EncoderInterface:
            tags: ['app.encoder']
        App\Service\Mailer\Builder\BuilderInterface:
            tags: [ 'app.mailer.builder' ]
        App\Service\Twig\AssetsExtension:
            tags: [ 'twig.extension' ]
        App\Service\Cron\CronjobInterface:
            tags: [ 'app.cronjob' ]
        App\Service\File\Storage\FileStorageInterface:
            tags: [ 'app.storage' ]

    App\Service\ServiceIterator\CurrentAccessExtensionIterator:
        - !tagged_iterator app.extensions.access
    App\Service\ServiceIterator\OptionalsRolesIterator:
        - !tagged_iterator app.optionalsroles
    App\Service\ServiceIterator\ExporterIterator:
        - !tagged_iterator app.exporter
    App\Service\ServiceIterator\EncoderIterator:
        - !tagged_iterator app.encoder
    App\Service\ServiceIterator\Mailer\BuilderIterator:
        - !tagged_iterator app.mailer.builder
    App\Service\ServiceIterator\CronjobIterator:
        - !tagged_iterator app.cronjob
    App\Service\ServiceIterator\StorageIterator:
        - !tagged_iterator app.storage

    #########################################
    ##  SERIALIZER Decorates ##
    App\Serializer\DefaultNormalizer:
        # By default .inner is passed as argument
        decorates: 'api_platform.jsonld.normalizer.item'

    app.serializer.normalizer.item.json:
        class: 'App\Serializer\DefaultNormalizer'
        decorates: 'api_platform.serializer.normalizer.item'

    App\Serializer\AccessContextBuilder:
        decorates: 'api_platform.serializer.context_builder'
        arguments: [ '@App\Serializer\AccessContextBuilder.inner' ]
        autoconfigure: false

    #########################################
    ##  LISTENER ##

    #########################################
    ##  ELASTIC SERVICE ##
    App\Service\Elasticsearch\EducationNotationUpdater:
        arguments:
            - '@fos_elastica.object_persister.search.educationNotation'

    #########################################
    ## AutoWiring du service container ##
    Symfony\Component\DependencyInjection\ContainerInterface: '@service_container'
    #########################################

