parameters:
  xcart.workers_pool_path: '%kernel.project_dir%/var/workers/'
  doctrine.dbal.connection_factory.class: XCart\Doctrine\DBAL\ConnectionFactory

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.
    public: true        # Temporary option to ise container as a service locator
    bind:
      $cartReadRepository: '@xcart.repository.cart.read'
      $cartWriteRepository: '@xcart.repository.cart.write'
      $cartItemReadRepository: '@xcart.repository.orderitem.read'
      $cartItemWriteRepository: '@xcart.repository.orderitem.write'
      $productReadRepository: '@xcart.repository.product.read'
      $productWriteRepository: '@xcart.repository.product.write'

  # makes classes in src/ available to be used as services
  # this creates a service per class whose id is the fully-qualified class name
  XCart\:
    resource: '../src/'
    exclude:
      - '../src/API/'
      - '../src/DataSource/'
      - '../src/DependencyInjection/'
      - '../src/Entity/'
      - '../src/Logic/'
      - '../src/Kernel.php'
      - '../src/Tests/'
      - '../src/Doctrine/DBAL/Schema/'
      - '../src/Doctrine/Migration/'
      - '../src/Domain/StaticConfigDomain.php'
      - '../src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php'
      - '../src/Symfony/Component/Lock/Stores/'
      - '../src/Framework/Symfony/'
      - '../src/Framework/Doctrine/'
      - '../src/Framework/ApiPlatform/Core/Api'
      - '../src/Framework/ApiPlatform/Core/Bridge/Symfony/Routing'
      - '../src/Transformer/XLite/Model/OrderItem/Logic/Entity/Storefront/Cart/Item'

  XCart\ServiceLocator: ~

  # common services
  xcart.logger: '@monolog.logger'

  xcart.auth:
    class: XLite\Core\Auth
    factory: ['XLite\Core\Auth', 'getInstance']

  XCart\Monolog\Handler\XCFileHandler:
    class: XCart\Monolog\Handler\XCFileHandler
    arguments:
      $path: '%kernel.logs_dir%'
      $file: '%env(string:LOGGER_FILE_STREAM_NAME)%'
      $skipDeprecation: '%env(bool:LOGGER_SKIP_DEPRECATIONS)%'
      $level: '%env(int:LOGGER_LEVEL)%'

  xcart.core.config:
    class: XLite\Core\ConfigCell
    factory: ['XLite\Core\Config', 'getInstance']

  xcart.core.translation:
    class: XLite\Core\Translation
    factory: ['XLite\Core\Translation', 'getInstance']

  xcart.xlite:
    class: XLite
    factory: ['XLite', 'getInstance']

  XCart\Monolog\Processor\Backtrace:
    arguments:
      $sourceAliases: []
      $level: '%env(int:LOGGER_LEVEL)%'
    tags:
      - {name: monolog.processor}

  XCart\Monolog\Processor\RouteProcessor:
    tags:
      - {name: monolog.processor}

  XCart\Monolog\Processor\ExecutionContextProcessor:
    tags:
      - {name: monolog.processor}

  Monolog\Processor\ProcessIdProcessor:
    tags:
      - {name: monolog.processor}

  Symfony\Bridge\Monolog\Processor\WebProcessor:
    tags:
      - {name: monolog.processor}

  Symfony\Bridge\Monolog\Processor\ConsoleCommandProcessor:
    arguments:
      $includeArguments: true
      $includeOptions: true
    tags:
      - {name: monolog.processor}

  Monolog\Processor\PsrLogMessageProcessor:
    tags:
      - {name: monolog.processor}

  Aws\CloudWatchLogs\CloudWatchLogsClient:
    arguments:
      - region: '%env(string:LOGGER_CLOUD_WATCH_REGION)%'
        version: '%env(string:LOGGER_CLOUD_WATCH_VERSION)%'
        credentials:
          key: '%env(string:LOGGER_CLOUD_WATCH_KEY)%'
          secret: '%env(string:LOGGER_CLOUD_WATCH_SECRET)%'
          token: '%env(string:LOGGER_CLOUD_WATCH_TOKEN)%'

  XCart\Monolog\Handler\CloudWatch:
    arguments:
      - '@Aws\CloudWatchLogs\CloudWatchLogsClient'
      - '%env(string:LOGGER_CLOUD_WATCH_GROUP_NAME)%'
      - '%env(string:LOGGER_CLOUD_WATCH_STREAM_NAME)%'
      - '%env(int:LOGGER_CLOUD_WATCH_RETENTION_DAYS)%'
      - 10000
      - []
      - '%env(string:LOGGER_LEVEL)%'


  # framework-level overrides & decorators
  XCart\Messenger\Transport\Sender\SendersLocator:
    decorates: messenger.senders_locator
    arguments:
      - '@XCart\Messenger\Transport\Sender\SendersLocator.inner'
      - '%env(bool:BACKGROUND_JOBS_ENABLED)%'

  # services
  xcart.listener.table_prefix:
    class: XCart\EventListener\TablePrefixEventListener
    calls:
      - [setConfig, ['%table_prefix%']]
    tags:
      - {name: doctrine.event_listener, event: loadClassMetadata, method: loadClassMetadata}

  kernel.doctrine.orm.entity_manager:
    class: XLite\Core\Doctrine\ORM\EntityManager
    decorates: doctrine.orm.entity_manager
    arguments: ["@kernel.doctrine.orm.entity_manager.inner"]

  XCart\Doctrine\ORM\Mapping\NamingStrategy:
    arguments:
      $default: '@doctrine.orm.naming_strategy.default'
      $underscoreNumberAware: '@doctrine.orm.naming_strategy.underscore_number_aware'

  XCart\EventListener\RunPostRequestActionsListener:
    tags:
      - {name: kernel.event_listener, event: kernel.terminate}

  XCart\EventListener\CleanUrlListener:
    tags:
      - {name: kernel.event_listener, event: kernel.request, priority: 5000}

  XCart\EventListener\KernelControllerInitListener:
    tags:
      - {name: kernel.event_listener, event: kernel.controller}

  XCart\EventListener\ExceptionListener:
    tags:
      - {name: kernel.event_listener, event: kernel.exception}

  XCart\EventListener\ModulesInitEventDispatcher:
    tags:
      - {name: kernel.event_listener, event: kernel.controller, method: dispatchModulesInitEvent}
      - {name: kernel.event_listener, event: console.command, method: dispatchModulesInitEvent}

  XCart\EventListener\CorsResponseListener:
    tags:
      - {name: kernel.event_listener, event: kernel.response}

  XLite\Core\Task\EventListener:
    tags:
      - {name: kernel.event_listener, event: xcart.cronjob, method: handleTask}

  XLite\Core\Task\DataCacheGarbageCleaner:
    tags:
      - {name: kernel.event_listener, event: xcart.cronjob, method: handleTask}

  XLite\Core\Task\OrdersGarbageCleaner:
    tags:
      - {name: kernel.event_listener, event: xcart.cronjob, method: handleTask}

  XLite\Core\Model\EntityVersion\EntityVersionUpdater:
    tags:
      - {name: doctrine.event_subscriber}

  XLite\Core\Model\CategoriesTreeUpdater:
    tags:
      - {name: doctrine.event_subscriber}

  XLite\Core\Model\ImageResizeScheduler:
    tags:
      - {name: doctrine.event_subscriber}

  XCart\EventListener\FixturesLoadedListener:
    tags:
      - {name: kernel.event_listener, event: xcart.service.post-fixtures-load, method: handlePostLoad}

  Doctrine\ORM\Tools\SchemaTool: ~

  Doctrine\Common\Annotations\DocParser: ~
  XCart\Extender\Action\ImportedAnnotationsParser: ~
  XCart\Extender\Action\AnnotationsParserInterface: '@XCart\Extender\Action\ImportedAnnotationsParser'
  XCart\Extender\Action\Parser: ~

  #    Symfony\Component\Yaml\Parser: ~

  XCart\Operation\Service\ViewList\ViewListRead:
    arguments:
      $sourcePath: '%kernel.project_dir%'
      $skinModel: '%xcart.skin_model%'

  XCart\Doctrine\Migration: ~
  XCart\Doctrine\Migration\MigrationInterface: '@XCart\Doctrine\Migration'

  XCart\Doctrine\FixtureLoader:
    arguments:
      $tablePrefix: '%env(resolve:DATABASE_DEFAULT_TABLE_PREFIX)%'

  XCart\Domain\ModuleManagerDomain:
    arguments:
      $modules: '%xcart.modules%'

  XCart\EventListener\SessionListener:
    tags:
      - {name: kernel.event_listener, event: kernel.response}

  XCart\EventListener\ConfigListener:
    tags:
      - {name: kernel.event_listener, event: kernel.request, priority: 256}

  XCart\EventListener\XCartBootListener:
    tags:
      - {name: kernel.event_listener, event: xcart.boot, method: onBoot}

  XCart\EventListener\LanguageListener:
    tags:
      - {name: kernel.event_listener, event: kernel.request, priority: 32}

  XCart\Command\Service\GetProtectedStructuresCommand:
    arguments:
      $sourcePath: '%kernel.project_dir%'

  xcart.api_resources.reader:
    class: XCart\Framework\Doctrine\Common\Annotations\Reader
    arguments:
      $inner: '@annotation_reader'
      $classNames: ['ApiPlatform\Core\Annotation\ApiResource']

  XLite\Console\Command\Utils\Import: ~

  XLite\Logger:
    factory: ['XLite\Logger', 'getInstance']

  XCart\Notification\InfoBlockManager:
    arguments:
      $auth: '@xcart.auth'

  XLite\Core\Templating\Twig\Functions: ~

  XLite\Core\Templating\Twig\Extension\XCartExtension:
    autowire: true
    tags: ['twig.extension']

  XLite\Core\Layout:
    factory: ['XLite\Core\Layout', 'getInstance']

  XCart\Twig\Loader\FilesystemLoader:
    decorates: twig.loader.native_filesystem
    arguments:
      - '@XCart\Twig\Loader\FilesystemLoader.inner'
      - '@XLite\Core\Layout'

  XLite\Core\Templating\TwigEngine:
    autowire: true

  XLite\Core\WidgetCache: ~
  XLite\Core\WidgetCacheManager: ~
  XLite\Core\Cache\CacheKeyPartsGenerator: ~
  XLite\Core\View\WidgetParamsSerializer: ~

  XLite\Core\View\DynamicWidgetRenderer:
    autowire: true

  XCart\DependencyInjection\TrailingSlashRemovingEnvVarProcessor:
    tags: ['container.env_var_processor']

  XCart\Doctrine\DBAL\ConnectionFactory:
    autowire: false

  XCart\Messenger\EventListener\WorkersRegistryEventListener:
    arguments:
      $workersPoolPath: '%xcart.workers_pool_path%'

  # tmp_vars
  XLite\Core\TmpVars:
    class: XLite\Core\TmpVars
    arguments:
      $repository: '@xcart.repository.tmpvar.write'

  XCart\Event\Service\DeferrerCallbackRunEvent:
    autowire: false
  XCart\Doctrine\CallbackManager\DeferredCallbackDto:
    autowire: false

  XCart\EntityCallback\ProfileCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: prePersist, entity: XLite\Model\Profile}
      - {name: doctrine.orm.entity_listener, event: preUpdate, entity: XLite\Model\Profile}

  XCart\EntityCallback\CountryCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: preRemove, entity: XLite\Model\Country}

  XCart\EntityCallback\StateCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: preRemove, entity: XLite\Model\State}

  XCart\EntityCallback\ImportLogCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: prePersist, entity: XLite\Model\ImportLog}

  XCart\EntityCallback\OrderHistoryEventsCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: prePersist, entity: XLite\Model\OrderHistoryEvents}
      - {name: doctrine.orm.entity_listener, event: preUpdate, entity: XLite\Model\OrderHistoryEvents}

  XCart\EntityCallback\AccessControlCellCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: prePersist, entity: XLite\Model\AccessControlCell}

  XCart\EntityCallback\TransactionCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: prePersist, entity: XLite\Model\Payment\Transaction}

  XCart\EntityCallback\PaymentMethodCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: preUpdate, entity: XLite\Model\Payment\Method}
      - {name: doctrine.orm.entity_listener, event: preRemove, entity: XLite\Model\Payment\Method}

  XCart\EntityCallback\PaymentMethodSettingCallback:
    tags:
      - { name: doctrine.orm.entity_listener, event: preUpdate, entity: XLite\Model\Payment\MethodSetting }

  XCart\EntityCallback\PaymentMethodTranslationCallback:
    tags:
      - { name: doctrine.orm.entity_listener, event: preUpdate, entity: XLite\Model\Payment\MethodTranslation }

  XCart\EntityCallback\ViewListCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: prePersist, entity: XLite\Model\ViewList}
      - {name: doctrine.orm.entity_listener, event: preRemove, entity: XLite\Model\ViewList}

  XCart\EntityCallback\StorageCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: prePersist, entity: XLite\Model\Base\Storage}
      - {name: doctrine.orm.entity_listener, event: preUpdate, entity: XLite\Model\Base\Storage}
      - {name: doctrine.orm.entity_listener, event: preRemove, entity: XLite\Model\Base\Storage}

  XCart\EntityCallback\CatalogCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: prePersist, entity: XLite\Model\Base\Catalog}
      - {name: doctrine.orm.entity_listener, event: preUpdate, entity: XLite\Model\Base\Catalog}

  XCart\EntityCallback\ProductCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: prePersist, entity: XLite\Model\Product}
      - {name: doctrine.orm.entity_listener, event: preUpdate, entity: XLite\Model\Product}
      - {name: doctrine.orm.entity_listener, event: postUpdate, entity: XLite\Model\Product}
      - {name: kernel.event_listener, event: deferrer.callback.run, method: runQuickData}

  XCart\EntityCallback\MembershipCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: postPersist, entity: XLite\Model\Membership}
      - {name: kernel.event_listener, event: deferrer.callback.run, method: runQuickData}

  XCart\EntityCallback\OrderCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: prePersist, entity: XLite\Model\Order}
      - {name: doctrine.orm.entity_listener, event: preUpdate, entity: XLite\Model\Order}

  XCart\EntityCallback\CartCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: prePersist, entity: XLite\Model\Cart}
      - {name: doctrine.orm.entity_listener, event: preUpdate, entity: XLite\Model\Cart}
      - {name: doctrine.orm.entity_listener, event: preRemove, entity: XLite\Model\Cart}

  XCart\EntityCallback\AttributeCallback:
    tags:
      - {name: doctrine.orm.entity_listener, event: postUpdate, entity: XLite\Model\Attribute}

  XLite\Core\Translation:
    factory: ['XLite\Core\Translation', 'getInstance']

  XLite\Core\OrderHistory:
    factory: ['XLite\Core\OrderHistory', 'getInstance']

  XCart\Security\Http\Authenticator\TokenRepositoryFactory:
    arguments:
      $restApiTokenRepository: '@XCart\Security\Http\Authenticator\TokenRepository\RestApiTokenRepository'
      $storefrontApiTokenRepository: '@XCart\Security\Http\Authenticator\TokenRepository\StorefrontApiTokenRepository'
