# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.

# 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
imports:
  - { resource: services/import.yml }
  - { resource: services/saas.yml }
  - { resource: services/bot.yml }

parameters:
  locale: 'uk'
  pagination.limit: 20
  sortBy: ['id.desc']
  filterBy: []
  importTemp: '%kernel.project_dir%/var/import'
  saas.app.validation.secret.key.request:
    method: 'GET'
    url: '%env(SAAS_VALIDATION_SECRET_KEY_ENDPOINT)%'
  saas.app.publish.secret.key.request:
    method: 'POST'
    url: '%env(SAAS_PUBLISH_SECRET_KEY_ENDPOINT)%'
  exportPath: '%kernel.project_dir%/var/export'


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.

  _instanceof:
    App\EventListener\DisableListenerInterface:
      tags:
        - { name: 'kernel.event_listener', event: 'App\Event\DisableListenerEvent', method: 'disable' }
  # 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,Entity,Migrations,Tests,Kernel.php}'

  # controllers are imported separately to make sure services can be injected
  # as action arguments even if you don't extend any base controller class
  App\Controller\:
    resource: '../src/Controller'
    tags: ['controller.service_arguments']

  # add more service definitions when explicit configuration is needed
  # please note that last definitions always *replace* previous ones

  App\EventListener\JsonDecodeRequestLister:
    tags: [{ name: kernel.event_listener, event: kernel.request }]
  App\EventListener\PaginationArgumentsListener:
    tags: [{ name: kernel.event_listener, event: kernel.controller }]
  App\EventListener\ValidationExceptionListener:
    tags: [{ name: kernel.event_listener, event: kernel.exception }]

  Symfony\Component\Translation\TranslatorBagInterface:
    alias: Symfony\Contracts\Translation\TranslatorInterface

  app.translator:
    alias: Symfony\Component\Translation\TranslatorBagInterface
    public: true

  App\Service\Import\File\Uploader:
    arguments:
      $importTemp: '%importTemp%'

  App\Service\Import\Result\SerializableResult:
    shared: false

  App\Service\Import\Handler\ItemHandlerInterface: '@import.handler.field.xlsx'
  App\Service\Import\Transformer\ChainValueTransformer: '@import.transformer.chain'

  App\Service\Validation\Resolver\ValidationGroupResolverInterface: '@App\Service\Validation\Resolver\ChainValidationGroupResolver'
  App\Service\Validation\Resolver\AgreementValidationGroupResolver:
    tags: ['app.validation_resolver']
  App\Service\Validation\Resolver\CounterpartyValidationGroupResolver:
    tags: ['app.validation_resolver']
  App\Service\Validation\Resolver\LandValidationGroupResolver:
    tags: ['app.validation_resolver']

  App\EventListener\SupplementaryAgreementListener:
    tags:
      - { name: 'doctrine.orm.entity_listener',event: 'prePersist', entity: 'App\Entity\Agreement' }
      - { name: 'doctrine.orm.entity_listener', event: 'preUpdate', entity: 'App\Entity\Agreement' }
  App\EventListener\EntityChangeListener:
    tags:
      - { name: 'doctrine.event_listener', event: 'postUpdate' }
      - { name: 'doctrine.event_listener', event: 'postPersist' }
      - { name: 'doctrine.event_listener', event: 'postRemove' }

  App\Service\Tests\Generator\EntityFactory:
    public: true

  App\Service\Saas\SecretKeyValidator:
    arguments:
      $httpClient: '@Symfony\Contracts\HttpClient\HttpClientInterface'
      $secretKeyValidationRequestConfig: '%saas.app.validation.secret.key.request%'

  App\Service\Saas\Api\Container:
    arguments:
      $config: '%saas.api.container%'

  App\Service\Saas\Api\Client:
    arguments:
      $httpClient: '@Symfony\Contracts\HttpClient\HttpClientInterface'
      $apiContainer: '@App\Service\Saas\Api\Container'

  App\Service\Saas\SecretKeyPublisher:
    arguments:
      $httpClient: '@Symfony\Contracts\HttpClient\HttpClientInterface'
      $secretKeyPublishRequestConfig: '%saas.app.publish.secret.key.request%'

  App\Service\Filter\FilterHandler:
    calls:
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\BetweenType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\WhereType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\DateType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\LocationType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\LandToFieldType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\ChangeSetRequisiteType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\LandOutsideType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\SubdivisionType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\MultipleSubdivisionType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\AgreementMultipleSubdivisionType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\PolygonType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\AgreementsType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\DocumentLocationType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\AgronomistConclusion']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\LandAgreementsSubType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\LandAgreementsType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\WithoutPaintType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\IntersectionAreaType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\AgreementsCounterpartyType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\FieldsIrrigatedType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\AgreementsEndYearType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\Finances\AgreementsType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\Finances\BuyerType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\Finances\SellerType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\Finances\TypeRentType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\LandExcludeReceivedInExchangeType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\AgreementsValidByDateLastType']]
      - [addFilterTypeBehavior, ['@App\Service\Filter\FilterType\CustomType\AgreementsTypes']]

  App\Service\TaskBoard\TaskBoardService:
    calls:
      - [addProvider, ['@App\Service\TaskBoard\Providers\FieldProvider']]
      - [addProvider, ['@App\Service\TaskBoard\Providers\LandProvider']]
      - [addProvider, ['@App\Service\TaskBoard\Providers\AgreementProvider']]

  #postgis
  Jsor\Doctrine\PostGIS\Event\ORMSchemaEventSubscriber:
    tags:
      - { name: doctrine.event_subscriber, connection: default }

  App\Service\Export\ExportHandler:
    calls:
      - [addFormatter, ['@App\Service\Export\Formatter\LandFormatter']]
      - [addFormatter, ['@App\Service\Export\Formatter\CounterpartiesFormatter']]
      - [addFormatter, ['@App\Service\Export\Formatter\FieldFormatter']]
      - [addFormatter, ['@App\Service\Export\Formatter\AgreementsFormatter']]
      - [addFormatter, ['@App\Service\Export\Formatter\AgreementsBaseFormatter']]
      - [addFormatter, ['@App\Service\Export\Formatter\AgreementsSupplementaryFormatter']]

  App\Service\Export\ExportKmlHandler:
    calls:
      - [addFormatter, ['@App\Service\Export\Formatter\Kml\FieldKmlFormatter']]


  App\Service\Export\Formatter\LandFormatter:
    arguments:
      $importConfig: '%import.configuration.land.xlsx%'

  App\Service\Export\Formatter\CounterpartiesFormatter:
    arguments:
      $importConfig: '%import.configuration.counterparty.xlsx%'

  App\Service\Export\Formatter\FieldFormatter:
    arguments:
      $importConfig: '%import.configuration.field.xlsx%'

  App\Service\Export\Formatter\AgreementsFormatter:
    arguments:
      $importConfig: '%import.configuration.agreement.xlsx%'

  App\Service\Export\Formatter\AgreementsBaseFormatter:
    arguments:
      $importConfig: '%import.configuration.agreement.xlsx%'

  App\Service\Export\File\CreatorFile:
    arguments:
      $path: '%exportPath%'

  app.postgis_geometry_validator:
    alias: App\Service\PostGis\Geometry\Validation\GeometryValidatorInterface
    public: true

  app.validator:
    alias: Symfony\Component\Validator\Validator\ValidatorInterface
    public: true

  App\Service\Bot\Api\Container:
    arguments:
      $config: '%bot.api.container%'

  App\Service\Bot\Api\Client:
    arguments:
      $httpClient: '@Symfony\Contracts\HttpClient\HttpClientInterface'
      $apiContainer: '@App\Service\Bot\Api\Container'
