parameters:
    prestashop.core.grid.data.factory.doctrine_grid_data_factory: PrestaShop\PrestaShop\Core\Grid\Data\Factory\DoctrineGridDataFactory
services:
    _defaults:
        public: true

    prestashop.core.grid.filter.form_factory:
        class: 'PrestaShop\PrestaShop\Core\Grid\Filter\GridFilterFormFactory'
        arguments:
            - '@form.factory'
            - '@prestashop.core.hook.dispatcher'

    # Grid data providers
    prestashop.core.grid.data_provider.log:
        class: '%prestashop.core.grid.data.factory.doctrine_grid_data_factory%'
        arguments:
            - '@prestashop.core.admin.log.repository'
            - '@prestashop.core.hook.dispatcher'
            - '@prestashop.core.grid.query.doctrine_query_parser'
            - 'logs'

    prestashop.core.grid.data_provider.email_logs:
        class: '%prestashop.core.grid.data.factory.doctrine_grid_data_factory%'
        arguments:
            - '@prestashop.core.grid.query_builder.email_logs'
            - '@prestashop.core.hook.dispatcher'
            - '@prestashop.core.grid.query.doctrine_query_parser'
            - 'email_logs'

    prestashop.core.grid.data_provider.request_sql:
        class: '%prestashop.core.grid.data.factory.doctrine_grid_data_factory%'
        arguments:
            - '@prestashop.core.admin.request_sql.repository'
            - '@prestashop.core.hook.dispatcher'
            - '@prestashop.core.grid.query.doctrine_query_parser'
            - 'request_sql'

    prestashop.core.grid.data_provider.webservice_key:
        class: '%prestashop.core.grid.data.factory.doctrine_grid_data_factory%'
        arguments:
            - '@prestashop.core.grid.query.webservice_key_query_builder'
            - '@prestashop.core.hook.dispatcher'
            - '@prestashop.core.grid.query.doctrine_query_parser'
            - 'webservice_key'

    prestashop.core.grid.data_provider.meta:
        class: '%prestashop.core.grid.data.factory.doctrine_grid_data_factory%'
        arguments:
            - '@prestashop.core.grid.query_builder.meta'
            - '@prestashop.core.hook.dispatcher'
            - '@prestashop.core.grid.query.doctrine_query_parser'
            - 'meta'

    # Grid definition factories
    prestashop.core.grid.definition.factory.abstract_grid_definition:
        class: 'PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory'
        abstract: true
        calls:
            - [setTranslator, ['@translator']]
            - [setHookDispatcher, ['@prestashop.core.hook.dispatcher']]

    prestashop.core.grid.definition.factory.logs:
        class: 'PrestaShop\PrestaShop\Core\Grid\Definition\Factory\LogGridDefinitionFactory'
        parent: 'prestashop.core.grid.definition.factory.abstract_grid_definition'
        arguments:
          - "@=service('router').generate('admin_common_reset_search', {'controller': 'logs', 'action': 'index'})"
          - "@=service('router').generate('admin_logs_index')"
        public: true

    prestashop.core.grid.definition.factory.email_logs:
        class: 'PrestaShop\PrestaShop\Core\Grid\Definition\Factory\EmailLogsDefinitionFactory'
        parent: 'prestashop.core.grid.definition.factory.abstract_grid_definition'
        arguments:
          - "@=service('router').generate('admin_common_reset_search', {'controller': 'email', 'action': 'index'})"
          - "@=service('router').generate('admin_emails_index')"
          - '@prestashop.core.form.choice_provider.language_by_id'
        public: true

    prestashop.core.grid.definition.factory.request_sql:
        class: 'PrestaShop\PrestaShop\Core\Grid\Definition\Factory\RequestSqlGridDefinitionFactory'
        parent: 'prestashop.core.grid.definition.factory.abstract_grid_definition'
        arguments:
            - "@=service('router').generate('admin_common_reset_search', {'controller': 'sqlmanager', 'action': 'index'})"
            - "@=service('router').generate('admin_sql_request')"
        public: true

    prestashop.core.grid.definition.factory.backup:
        class: 'PrestaShop\PrestaShop\Core\Grid\Definition\Factory\BackupDefinitionFactory'
        parent: 'prestashop.core.grid.definition.factory.abstract_grid_definition'
        public: true

    prestashop.core.grid.definition.factory.webservice_key:
        class: 'PrestaShop\PrestaShop\Core\Grid\Definition\Factory\WebserviceKeyDefinitionFactory'
        parent: 'prestashop.core.grid.definition.factory.abstract_grid_definition'
        arguments:
            - '@=service("prestashop.core.form.choice_provider.status").getChoices()'
            - "@=service('router').generate('admin_common_reset_search', {'controller': 'webservice', 'action': 'index'})"
            - "@=service('router').generate('admin_webservice')"
        public: true

    prestashop.core.grid.definition.factory.meta:
        class: 'PrestaShop\PrestaShop\Core\Grid\Definition\Factory\MetaGridDefinitionFactory'
        parent: 'prestashop.core.grid.definition.factory.abstract_grid_definition'
        arguments:
            - "@=service('router').generate('admin_common_reset_search', {'controller': 'meta', 'action': 'index'})"
            - "@=service('router').generate('admin_metas_index')"
        public: true

    # Grid factories
    prestashop.core.grid.log_factory:
        class: 'PrestaShop\PrestaShop\Core\Grid\GridFactory'
        arguments:
            - '@prestashop.core.grid.definition.factory.logs'
            - '@prestashop.core.grid.data_provider.log'
            - '@prestashop.core.grid.filter.form_factory'
            - '@prestashop.core.hook.dispatcher'

    prestashop.core.grid.factory.email_logs:
        class: 'PrestaShop\PrestaShop\Core\Grid\GridFactory'
        arguments:
            - '@prestashop.core.grid.definition.factory.email_logs'
            - '@prestashop.core.grid.data_provider.email_logs'
            - '@prestashop.core.grid.filter.form_factory'
            - '@prestashop.core.hook.dispatcher'

    prestashop.core.grid.factory.request_sql:
        class: 'PrestaShop\PrestaShop\Core\Grid\GridFactory'
        arguments:
            - '@prestashop.core.grid.definition.factory.request_sql'
            - '@prestashop.core.grid.data_provider.request_sql'
            - '@prestashop.core.grid.filter.form_factory'
            - '@prestashop.core.hook.dispatcher'

    prestashop.core.grid.factory.backup:
        class: 'PrestaShop\PrestaShop\Core\Grid\GridFactory'
        arguments:
            - '@prestashop.core.grid.definition.factory.backup'
            - '@prestashop.core.backup.listing.grid_data_factory'
            - '@prestashop.core.grid.filter.form_factory'
            - '@prestashop.core.hook.dispatcher'

    prestashop.core.grid.factory.webservice_key:
        class: 'PrestaShop\PrestaShop\Core\Grid\GridFactory'
        arguments:
            - '@prestashop.core.grid.definition.factory.webservice_key'
            - '@prestashop.core.grid.data_provider.webservice_key'
            - '@prestashop.core.grid.filter.form_factory'
            - '@prestashop.core.hook.dispatcher'

    prestashop.core.grid.factory.meta:
        class: 'PrestaShop\PrestaShop\Core\Grid\GridFactory'
        arguments:
            - '@prestashop.core.grid.definition.factory.meta'
            - '@prestashop.core.grid.data_provider.meta'
            - '@prestashop.core.grid.filter.form_factory'
            - '@prestashop.core.hook.dispatcher'

    # Grid presenter
    prestashop.core.grid.presenter.grid_presenter:
        class: 'PrestaShop\PrestaShop\Core\Grid\Presenter\GridPresenter'
        arguments:
            - '@prestashop.core.hook.dispatcher'

    # Grid Query builder
    prestashop.core.grid.abstract_query_builder:
        class: 'PrestaShop\PrestaShop\Core\Grid\Query\AbstractDoctrineQueryBuilder'
        abstract: true
        arguments:
            - '@doctrine.dbal.default_connection'
            - '%database_prefix%'

    prestashop.core.grid.query_builder.email_logs:
        class: 'PrestaShop\PrestaShop\Core\Grid\Query\EmailLogsQueryBuilder'
        parent: 'prestashop.core.grid.abstract_query_builder'
        public: true
        arguments:
            - '@prestashop.core.query.doctrine_search_criteria_applicator'

    prestashop.core.grid.query.webservice_key_query_builder:
        class: 'PrestaShop\PrestaShop\Core\Grid\Query\WebserviceKeyQueryBuilder'
        parent: 'prestashop.core.grid.abstract_query_builder'
        arguments:
            - '@prestashop.core.query.doctrine_search_criteria_applicator'
        public: true

    prestashop.core.grid.query_builder.meta:
        class: 'PrestaShop\PrestaShop\Core\Grid\Query\MetaQueryBuilder'
        parent: 'prestashop.core.grid.abstract_query_builder'
        arguments:
            - '@prestashop.core.query.doctrine_search_criteria_applicator'
            - "@=service('prestashop.adapter.legacy.context').getContext().language.id"
            - "@=service('prestashop.adapter.legacy.context').getContext().shop.id"
        public: true

    # Grid Query parser
    prestashop.core.grid.query.doctrine_query_parser:
        class: 'PrestaShop\PrestaShop\Core\Grid\Query\DoctrineQueryParser'

    prestashop.core.query.doctrine_search_criteria_applicator:
        class: 'PrestaShop\PrestaShop\Core\Grid\Query\DoctrineSearchCriteriaApplicator'

    # Grid position updater
    prestashop.core.grid.position.position_update_factory:
        class: 'PrestaShop\PrestaShop\Core\Grid\Position\PositionUpdateFactory'
        arguments:
            - 'positions'
            - 'rowId'
            - 'oldPosition'
            - 'newPosition'
            - 'parentId'

    prestashop.core.grid.position.update_handler.doctrine_position_update_handler:
        class: 'PrestaShop\PrestaShop\Core\Grid\Position\UpdateHandler\DoctrinePositionUpdateHandler'
        arguments:
            - '@doctrine.dbal.default_connection'
            - '%database_prefix%'

    prestashop.core.grid.position.doctrine_grid_position_updater:
        class: 'PrestaShop\PrestaShop\Core\Grid\Position\GridPositionUpdater'
        arguments:
            - '@prestashop.core.grid.position.update_handler.doctrine_position_update_handler'
