services:
    content_management.type_repository:
        class: Rawafed\ContentManagementBundle\Entity\Repository\ContentTypeRepository
        factory: [@doctrine.orm.default_entity_manager, getRepository]
        arguments:
            - \Rawafed\ContentManagementBundle\Entity\ContentType

    content_management.entry_repository:
        class: Rawafed\ContentManagementBundle\Entity\Repository\EntryRepository
        factory: ["@doctrine.orm.default_entity_manager", getRepository]
        arguments:
            - \Rawafed\ContentManagementBundle\Entity\Entry

    content.type_manager:
        class: Rawafed\ContentManagementBundle\Service\ContentTypeManager
        arguments: ["@content_management.type_repository", "@twig", "@router", "%entries.types%", "%kernel.root_dir%", "@service_container"]

    content.entry_manager:
        class: Rawafed\ContentManagementBundle\Service\EntryManager
        arguments: [@content_management.entry_repository, @content_management.config_resolver, @?reporting.reporting_service]

    oembed_provider:
        class: Rawafed\ContentManagementBundle\Service\OEmbedProvider
        arguments: [%website_title%, @router]

    content_management.config_resolver:
        class: Rawafed\ContentManagementBundle\Service\ContentConfigurationResolver
        arguments: [@service_container]

    content_management.menu:
        class: Rawafed\ContentManagementBundle\Service\ContentManagementMenu
        # Inject service container to avoid circular reference
        arguments: [@service_container]
        tags:
            - { name: admin.menu }

    regex_search_engine:
        class: Rawafed\ContentManagementBundle\Search\RegexSearchEngine
        arguments: ["@content_management.entry_repository", "@authors.author_repository"]

    fulltext_search_engine:
        class: Rawafed\ContentManagementBundle\Search\FullTextSearchEngine
        arguments: ["@content_management.entry_repository", "@authors.author_repository"]

    #===============================================================================
    # Doctrine entity listeners:
    content_management.entry_event_listener:
        class: Rawafed\ContentManagementBundle\Service\EntryEventListener
        arguments: [@event_dispatcher]
        tags:
            - { name: doctrine.orm.entity_listener }

    content_management.entry_property_helper:
        class: Rawafed\ContentManagementBundle\Service\EntryPropertyEventListener
        arguments: [%content_management.properties%]
        tags:
            - { name: doctrine.orm.entity_listener }

    content_management.entry_resource_event_listener:
        class: Rawafed\ContentManagementBundle\Service\EntryResourceEventListener
        arguments: [@content_management.config_resolver, @event_dispatcher]
        tags:
            - { name: doctrine.orm.entity_listener }

    #===============================================================================
    # Feed providers:
    content_management.content_type_feed_provider:
        class: Rawafed\ContentManagementBundle\FeedProviders\ContentTypeFeedProvider
        arguments: [@content.type_manager, @router, @content_management.entry_repository]
        tags:
            -  { name: feed_provider }

    content_management.category_feed_provider:
        class: Rawafed\ContentManagementBundle\FeedProviders\CategoryFeedProvider
        arguments: [@router, @doctrine.orm.default_entity_manager]
        tags:
            -  { name: feed_provider }

    #===============================================================================
    # Kernel event listeners:
    content_management.listener.indexing:
        class: Rawafed\ContentManagementBundle\Search\IndexingEventListener
        arguments: [@content.type_manager, @doctrine.orm.entity_manager]
        tags:
            - { name: kernel.event_listener, event: search_engine.indexing, priority:64, method: onIndexing }

    content_management.listener.search_engine_index_update:
        class: Rawafed\ContentManagementBundle\Search\IndexUpdater
        arguments: [@?solr_indexer]
        tags:
            - { name: kernel.event_listener, event: entry.publish, method: onPublish }
            - { name: kernel.event_listener, event: entry.update, method: onUpdate }
            - { name: kernel.event_listener, event: entry.unpublish, method: onUnPublish }

    content_management.listener.entry_resource_tasks:
        class: Rawafed\ContentManagementBundle\Service\EntryResourceTasks
        arguments: [@rawafed_tq.task_queue, @content_management.config_resolver, @doctrine.orm.entity_manager]
        tags:
            - { name: kernel.event_listener, event: entry_resource.create, method: onCreate }
            - { name: kernel.event_listener, event: entry_resource.update, method: onUpdate }
            - { name: kernel.event_listener, event: task.done, method: updateProperties }

    content_management.poster_generator:
        class: Rawafed\ContentManagementBundle\Service\PosterGenerator
        arguments: [@content_management.entry_repository, @content.entry_manager, @twig, @rawafed.image_manipulator]
        tags:
            - { name: kernel.event_listener, event: kernel.request, priority:128, method: onKernelRequest }

    #===============================================================================
    # Form types:
    content_management.form_type.collection_selector:
        class: Rawafed\ContentManagementBundle\Form\Type\CollectionSelectorType
        arguments: [@doctrine]
        tags:
            - { name: form.type, alias: collection_selector }

    content_management.form_type.entry_selector:
        class: Rawafed\ContentManagementBundle\Form\Type\EntrySelectorType
        arguments: [@doctrine]
        tags:
            - { name: form.type, alias: entry_selector }

    content_management.form_type.content_section:
        class: Rawafed\ContentManagementBundle\Form\ContentSectionType
        tags:
            - { name: form.type, alias: section }

    content_management.form_type.content_source:
        class: Rawafed\ContentManagementBundle\Form\ContentSourceType
        tags:
            - { name: form.type, alias: content_source }



    #=======================================================
    # content types jobs handlers
    rawafed.content.general.job_handler:
        class: Rawafed\ContentManagementBundle\JobsHandlers\ContentJobHandler
        arguments: [@router, @doctrine.orm.entity_manager, @mailer, @templating, "%locale%", "%islamic_content.sender.email%", "%islamic_content.sender.name%"]
        tags:
          - { name: 'job_handler', alias: 'content_job_handler' }

    #articles
    rawafed.content.articles.job_handler:
        class: Rawafed\ContentManagementBundle\JobsHandlers\ArticlesJobHandler
        arguments: [@router, @doctrine.orm.entity_manager, @mailer, @templating, "%locale%", "%islamic_content.sender.email%", "%islamic_content.sender.name%"]
        tags:
          - { name: 'job_handler', alias: 'articles_job_handler' }
