parameters:
    ps_root_dir:              "%kernel.root_dir%/../"
    ps_config_dir:            "%ps_root_dir%config"
    translations_dir:         "%kernel.root_dir%/Resources/translations"
    themes_translations_dir:  "%kernel.cache_dir%/themes"
    themes_dir:               "%kernel.root_dir%/../themes"

services:
    _defaults:
        public: true

# CORE ADMIN (prestashop.core.admin.*)
    # URL generation
    prestashop.core.admin.url_generator_factory:
        class: PrestaShopBundle\Service\TransitionalBehavior\AdminUrlGeneratorFactory
        arguments:
            - "@router"
    prestashop.core.admin.url_generator_legacy:
        class: Symfony\Component\Routing\Generator\UrlGeneratorInterface
        factory: ["@prestashop.core.admin.url_generator_factory", forLegacy]
        arguments:
            - "@prestashop.adapter.legacy.context"
    prestashop.core.admin.url_generator:
        class: Symfony\Component\Routing\Generator\UrlGeneratorInterface
        factory: ["@prestashop.core.admin.url_generator_factory", forSymfony]
    prestashop.core.admin.search_parameters:
        class: PrestaShop\PrestaShop\Core\Search\SearchParameters

    # Interfaced services to decorate
    prestashop.core.admin.data_provider.product_interface:
        class: PrestaShopBundle\Service\DataProvider\Admin\ProductInterface
    prestashop.core.admin.data_updater.product_interface:
        class: PrestaShopBundle\Service\DataUpdater\Admin\ProductInterface
    prestashop.core.admin.page_preference_interface:
        class: PrestaShopBundle\Service\TransitionalBehavior\AdminPagePreferenceInterface
    prestashop.core.admin.data_provider.addons_interface:
        class: PrestaShopBundle\Service\DataProvider\Admin\AddonsInterface
    prestashop.core.admin.data_provider.module_interface:
        class: PrestaShopBundle\Service\DataProvider\Admin\ModuleInterface

# ADAPTERS (prestashop.adapter.*)
    # Legacy context service, transitional
    prestashop.adapter.legacy.context:
        class: PrestaShop\PrestaShop\Adapter\LegacyContext
    # Adapter services that decorates interfaced services
    prestashop.adapter.admin.data_provider.product:
        class: PrestaShop\PrestaShop\Adapter\Product\AdminProductDataProvider
        decorates: prestashop.core.admin.data_provider.product_interface
        arguments:
            - "@doctrine.orm.entity_manager"
            - "@prestashop.adapter.image_manager"
        public: false
    prestashop.adapter.admin.data_updater.product:
        class: PrestaShop\PrestaShop\Adapter\Product\AdminProductDataUpdater
        decorates: prestashop.core.admin.data_updater.product_interface
        public: false
        arguments:
            - "@prestashop.hook.dispatcher"
    prestashop.adapter.admin.wrapper.product:
        class: PrestaShop\PrestaShop\Adapter\Product\AdminProductWrapper
        arguments: ["@translator", "@prestashop.adapter.legacy.context"]
    prestashop.adapter.admin.page_preference:
        class: PrestaShop\PrestaShop\Adapter\Admin\PagePreference
        arguments:
            - "@session"
        decorates: prestashop.core.admin.page_preference_interface
        public: false
    prestashop.adapter.admin.controller.category:
        class: PrestaShop\PrestaShop\Adapter\Category\AdminCategoryControllerWrapper

    prestashop.adapter.admin.data_provider.addons:
        class: PrestaShop\PrestaShop\Adapter\Addons\AddonsDataProvider
        decorates: prestashop.core.admin.data_provider.addons_interface
        arguments:
            - '@prestashop.addons.client_api'
            - '@prestashop.module.zip.manager'
        properties:
            cacheDir: "%kernel.cache_dir%"
        public: false

    prestashop.adapter.admin.data_provider.module:
        class: PrestaShop\PrestaShop\Adapter\Module\AdminModuleDataProvider
        arguments:
             - "@translator"
             - "@logger"
             - "@prestashop.core.admin.data_provider.addons_interface"
             - "@prestashop.categories_provider"
             - "@prestashop.adapter.data_provider.module"
             - "@doctrine.cache.provider"
             - "@=service('prestashop.adapter.legacy.context').getContext().employee"
        calls:
            - [ setRouter, ['@router']]
        decorates: prestashop.core.admin.data_provider.module_interface
        public: false

    prestashop.adapter.admin.controller.attribute_generator:
        class: PrestaShop\PrestaShop\Adapter\Attribute\AdminAttributeGeneratorControllerWrapper

    prestashop.adapter.module.self_configurator:
        class: PrestaShop\PrestaShop\Adapter\Module\Configuration\ModuleSelfConfigurator
        arguments:
            - "@prestashop.core.admin.module.repository"
            - "@prestashop.adapter.legacy.configuration"
            - "@doctrine.dbal.default_connection"
            - "@filesystem"

    # PRESTATRUST
    prestashop.adapter.module.prestatrust.checker:
        class: PrestaShop\PrestaShop\Adapter\Module\PrestaTrust\PrestaTrustChecker
        arguments:
            - "@doctrine.cache.provider"
            - "@prestashop.addons.client_api"
            - "@translator"

    prestashop.adapter.module.prestatrust.eventsubscriber:
        class: PrestaShop\PrestaShop\Adapter\Module\PrestaTrust\ModuleEventSubscriber
        arguments:
            - "@prestashop.adapter.module.prestatrust.checker"
        properties:
             enabled: '%prestashop.addons.prestatrust.enabled%'
        tags:
            - { name: kernel.event_subscriber }

    # MODULE TAB MANAGEMENT
    prestashop.adapter.module.tab.register:
        class: PrestaShop\PrestaShop\Adapter\Module\Tab\ModuleTabRegister
        arguments:
            - "@prestashop.core.admin.tab.repository"
            - "@prestashop.core.admin.lang.repository"
            - "@logger"
            - "@translator"
            - "@filesystem"
            - "@=service('prestashop.adapter.legacy.context').getLanguages()"

    prestashop.adapter.module.tab.unregister:
        class: PrestaShop\PrestaShop\Adapter\Module\Tab\ModuleTabUnregister
        arguments:
            - "@prestashop.core.admin.tab.repository"
            - "@prestashop.core.admin.lang.repository"
            - "@logger"
            - "@translator"

    prestashop.adapter.module.tab.eventsubscriber:
        class: PrestaShop\PrestaShop\Adapter\Module\Tab\ModuleTabManagementSubscriber
        arguments:
            - "@prestashop.adapter.module.tab.register"
            - "@prestashop.adapter.module.tab.unregister"
        tags:
            - { name: kernel.event_subscriber }

    #SECURITY
    prestashop.adapter.security.admin:
        class: "%AdapterSecurityAdminClass%"
        arguments:
            - "@prestashop.adapter.legacy.context"
            - "@security.token_storage"
            - "@prestashop.security.admin.provider"
        tags:
            - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }

    prestashop.access_denied.listener:
        class: PrestaShopBundle\EventListener\AccessDeniedListener
        arguments:
            - "@router"
            - "@translator"
            - "@session"
        tags:
            - { name: kernel.event_listener, event: kernel.exception, method: onKernelException }

    prestashop.demo_mode_enabled.listener:
        class: PrestaShopBundle\EventListener\DemoModeEnabledListener
        arguments:
            - "@router"
            - "@translator"
            - "@session"
            - "@annotation_reader"
            - "@=service('prestashop.adapter.legacy.configuration').getBoolean('_PS_MODE_DEMO_')"
        tags:
            - { name: kernel.event_listener, event: kernel.controller, method: onKernelController }

    prestashop.security.admin.provider:
        class: PrestaShopBundle\Security\Admin\EmployeeProvider
        arguments:
            - "@prestashop.adapter.legacy.context"

    prestashop.user_locale.listener:
        class: PrestaShopBundle\EventListener\UserLocaleListener
        arguments:
            - "@prestashop.adapter.legacy.context"
        tags:
            - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: 15 }

    #UTILS
    prestashop.utils.zip_manager:
        class: PrestaShopBundle\Utils\ZipManager

    #TRANSLATIONS FACTORIES
    prestashop.translation.translations_factory:
        class: PrestaShopBundle\Translation\Factory\TranslationsFactory

    ps.translations_factory:
        alias: "prestashop.translation.translations_factory"

    prestashop.translation.theme_translations_factory:
        class: PrestaShopBundle\Translation\Factory\ThemeTranslationsFactory
        arguments: ['@prestashop.translation.theme_provider']
        calls:
            - [ addProvider, ['@prestashop.translation.theme_provider']]

    ps.theme_translations_factory:
        alias: "prestashop.translation.theme_translations_factory"

    #TRANSLATIONS PROVIDERS
    prestashop.translation.backoffice_provider:
        class: PrestaShopBundle\Translation\Provider\BackOfficeProvider
        arguments:
            - "@prestashop.translation.database_loader"
            - "%translations_dir%"
        tags:
            - { name: "ps.translation_provider" }

    prestashop.translation.frontoffice_provider:
        class: PrestaShopBundle\Translation\Provider\FrontOfficeProvider
        arguments:
            - "@prestashop.translation.database_loader"
            - "%translations_dir%"
        tags:
            - { name: "ps.translation_provider" }

    prestashop.translation.mails:
        class: PrestaShopBundle\Translation\Provider\MailsProvider
        arguments:
            - "@prestashop.translation.database_loader"
            - "%translations_dir%"
        tags:
            - { name: "ps.translation_provider" }

    prestashop.translation.others_provider:
            class: PrestaShopBundle\Translation\Provider\OthersProvider
            arguments:
                - "@prestashop.translation.database_loader"
                - "%translations_dir%"
            tags:
                - { name: "ps.translation_provider" }

    prestashop.translation.theme_provider:
        class: PrestaShopBundle\Translation\Provider\ThemeProvider
        arguments:
            - "@prestashop.translation.database_loader"
            - "%themes_translations_dir%"
        properties:
            themeResourcesDirectory:  "%themes_dir%"
            filesystem:               "@filesystem"
            themeRepository:          "@prestashop.core.addon.theme.repository"
            themeExtractor:           "@prestashop.translation.theme_extractor"
            defaultTranslationDir:    "%translations_dir%"

    prestashop.translation.modules_provider:
        class: PrestaShopBundle\Translation\Provider\ModulesProvider
        arguments:
            - "@prestashop.translation.database_loader"
            - "%translations_dir%"
        tags:
            - { name: "ps.translation_provider" }

    prestashop.translation.module_provider:
        class: PrestaShopBundle\Translation\Provider\ModuleProvider
        arguments:
            - "@prestashop.translation.database_loader"
            - "%translations_dir%"
        tags:
            - { name: "ps.translation_provider" }

    prestashop.translation.search_provider:
        class: PrestaShopBundle\Translation\Provider\SearchProvider
        arguments:
            - "@prestashop.translation.database_loader"
            - "%translations_dir%"
        tags:
            - { name: "ps.translation_provider" }

    # TRANSLATIONS
    prestashop.translation.database_loader:
        class: PrestaShopBundle\Translation\Loader\DatabaseTranslationLoader
        arguments:
            - "@doctrine.orm.entity_manager"
        tags:
            - {name: translation.loader, alias: db}

    prestashop.translation.theme_extractor:
        class: PrestaShopBundle\Translation\Extractor\ThemeExtractor
        arguments:
            - "@prestashop.translation.extractor.smarty"


    prestashop.translation.dumper.xliff:
        class: PrestaShop\TranslationToolsBundle\Translation\Dumper\XliffFileDumper

    prestashop.translation.theme.exporter:
        class: PrestaShopBundle\Translation\Exporter\ThemeExporter
        arguments:
            - "@prestashop.translation.theme_extractor"
            - "@prestashop.translation.theme_provider"
            - "@prestashop.core.addon.theme.repository"
            - "@prestashop.translation.dumper.xliff"
            - "@prestashop.utils.zip_manager"
            - "@filesystem"
        properties:
            cacheDir: "%kernel.cache_dir%"
        calls:
            - [ setExportDir, ["%kernel.cache_dir%/export"]]


    # EVENT MANAGEMENT
    prestashop.dispatcher.legacy_hooks.subscriber:
        class: 'PrestaShopBundle\EventListener\ActionDispatcherLegacyHooksSubscriber'
        arguments: ['@prestashop.hook.dispatcher']
        tags:
            - { name: kernel.event_subscriber }

    # Custom Twig loader
    prestashop.module_kernel.repository:
        class: 'PrestaShopBundle\Kernel\ModuleRepository'
        arguments: ['@doctrine.dbal.default_connection', '%database_prefix%']

    prestashop.twig.modules.loader:
        class: 'PrestaShopBundle\Twig\Locator\ModuleTemplateLoader'
        arguments:
          -
            'PrestaShop': ''
            'Product': '/Admin/Product'
            'Twig': '/Admin/TwigTemplateForm'
            'AdvancedParameters': '/Admin/Configure/AdvancedParameters'
            'ShopParameters': '/Admin/Configure/ShopParameters'
          - '@=service("prestashop.module_kernel.repository").getActiveModulesPaths()'
        tags:
          - { name: twig.loader, priority: 1}
