<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
    <parameters>
        <parameter type="collection" key="shopware.media.metadata.types">
            <parameter type="string">\Shopware\Core\Content\Media\Metadata\Type\ImageMetadata</parameter>
            <parameter type="string">\Shopware\Core\Content\Media\Metadata\Type\DocumentMetadata</parameter>
            <parameter type="string">\Shopware\Core\Content\Media\Metadata\Type\VideoMetadata</parameter>
        </parameter>
    </parameters>
    <services>
        <!-- Entity definitions -->
        <service id="Shopware\Core\Content\Media\MediaDefinition">
            <tag name="shopware.entity.definition"/>
            <tag name="shopware.entity.hookable"/>
        </service>

        <service id="Shopware\Core\Content\Media\Aggregate\MediaDefaultFolder\MediaDefaultFolderDefinition">
            <tag name="shopware.entity.definition"/>
        </service>

        <service id="Shopware\Core\Content\Media\Aggregate\MediaThumbnail\MediaThumbnailDefinition">
            <tag name="shopware.entity.definition"/>
        </service>

        <service id="Shopware\Core\Content\Media\Aggregate\MediaTranslation\MediaTranslationDefinition">
            <tag name="shopware.entity.definition"/>
        </service>

        <service id="Shopware\Core\Content\Media\Aggregate\MediaFolder\MediaFolderDefinition">
            <tag name="shopware.entity.definition"/>
        </service>

        <service id="Shopware\Core\Content\Media\Aggregate\MediaThumbnailSize\MediaThumbnailSizeDefinition">
            <tag name="shopware.entity.definition"/>
        </service>

        <service id="Shopware\Core\Content\Media\Aggregate\MediaFolderConfiguration\MediaFolderConfigurationDefinition">
            <tag name="shopware.entity.definition"/>
        </service>

        <service id="Shopware\Core\Content\Media\Aggregate\MediaFolderConfigurationMediaThumbnailSize\MediaFolderConfigurationMediaThumbnailSizeDefinition">
            <tag name="shopware.entity.definition"/>
        </service>

        <service id="Shopware\Core\Content\Media\Aggregate\MediaTag\MediaTagDefinition">
            <tag name="shopware.entity.definition"/>
        </service>
        <!-- end of Entity definitions -->

        <!-- message handlers -->
        <service id="Shopware\Core\Content\Media\Message\GenerateThumbnailsHandler">
            <argument type="service" id="Shopware\Core\Content\Media\Thumbnail\ThumbnailService"/>
            <argument type="service" id="media.repository"/>
            <argument>%shopware.media.remote_thumbnails.enable%</argument>

            <tag name="messenger.message_handler"/>
        </service>

        <service id="Shopware\Core\Content\Media\Message\DeleteFileHandler">
            <argument type="service" id="shopware.filesystem.public"/>
            <argument type="service" id="shopware.filesystem.private"/>

            <tag name="messenger.message_handler"/>
        </service>
        <!-- end of message handlers -->

        <service id="Shopware\Core\Content\Media\Subscriber\MediaLoadedSubscriber">
            <!-- unseralize read optimized (serialized) database objects > restores thumbnails from `RO` into real property-->
            <tag name="kernel.event_listener" event="media.loaded" method="unserialize" priority="100" />
        </service>

        <service id="Shopware\Core\Content\Media\Subscriber\MediaFolderConfigLoadedSubscriber">
            <tag name="kernel.event_subscriber"/>
        </service>

        <!--File Services-->
        <service id="Shopware\Core\Content\Media\File\FileService">
        </service>

        <service id="Shopware\Core\Content\Media\File\FileFetcher">
            <argument type="service" id="Shopware\Core\Content\Media\File\FileUrlValidatorInterface" />
            <argument type="service" id="Shopware\Core\Content\Media\File\FileService" />
            <argument>%shopware.media.enable_url_upload_feature%</argument>
            <argument>%shopware.media.enable_url_validation%</argument>
            <argument>%shopware.media.url_upload_max_size%</argument>
        </service>

        <service class="Shopware\Core\Content\Media\File\FileUrlValidator" id="Shopware\Core\Content\Media\File\FileUrlValidatorInterface">
        </service>

        <service id="Shopware\Core\Content\Media\File\FileSaver" public="true">
            <argument type="service" id="media.repository"/>
            <argument type="service" id="shopware.filesystem.public"/>
            <argument type="service" id="shopware.filesystem.private"/>
            <argument type="service" id="Shopware\Core\Content\Media\Thumbnail\ThumbnailService"/>
            <argument type="service" id="Shopware\Core\Content\Media\Metadata\MetadataLoader"/>
            <argument type="service" id="Shopware\Core\Content\Media\TypeDetector\TypeDetector"/>
            <argument type="service" id="messenger.default_bus" />
            <argument type="service" id="event_dispatcher" />
            <argument type="service" id="Shopware\Core\Content\Media\Core\Application\MediaLocationBuilder" />
            <argument type="service" id="Shopware\Core\Content\Media\Core\Application\AbstractMediaPathStrategy" />
            <argument>%shopware.filesystem.allowed_extensions%</argument>
            <argument>%shopware.filesystem.private_allowed_extensions%</argument>
            <argument>%shopware.media.remote_thumbnails.enable%</argument>
        </service>

        <service id="Shopware\Core\Content\Media\File\FileLoader">
            <argument type="service" id="shopware.filesystem.public"/>
            <argument type="service" id="shopware.filesystem.private"/>
            <argument type="service" id="media.repository"/>
            <argument type="service" id="Nyholm\Psr7\Factory\Psr17Factory"/>
        </service>

        <service id="Shopware\Core\Content\Media\File\FileNameProvider" class="Shopware\Core\Content\Media\File\WindowsStyleFileNameProvider">
            <argument type="service" id="media.repository"/>
        </service>

        <service id="Shopware\Core\Content\Media\File\DownloadResponseGenerator">
            <argument type="service" id="shopware.filesystem.public"/>
            <argument type="service" id="shopware.filesystem.private"/>
            <argument type="service" id="Shopware\Core\Content\Media\MediaService"/>
            <argument>%shopware.filesystem.private_local_download_strategy%</argument>
            <argument type="service" id="Shopware\Core\Content\Media\Core\Application\AbstractMediaUrlGenerator"/>
            <argument>%shopware.filesystem.private_local_path_prefix%</argument>
        </service>

        <!-- Commands -->
        <service id="Shopware\Core\Content\Media\Commands\GenerateThumbnailsCommand">
            <argument type="service" id="Shopware\Core\Content\Media\Thumbnail\ThumbnailService"/>
            <argument type="service" id="media.repository"/>
            <argument type="service" id="media_folder.repository"/>
            <argument type="service" id="messenger.default_bus"/>
            <argument>%shopware.media.remote_thumbnails.enable%</argument>

            <tag name="console.command"/>
        </service>

        <service id="Shopware\Core\Content\Media\Commands\GenerateMediaTypesCommand">
            <argument type="service" id="Shopware\Core\Content\Media\TypeDetector\TypeDetector"/>
            <argument type="service" id="media.repository"/>

            <tag name="console.command"/>
        </service>

        <service id="Shopware\Core\Content\Media\Commands\DeleteNotUsedMediaCommand" shared="false">
            <argument type="service" id="Shopware\Core\Content\Media\UnusedMediaPurger"/>
            <argument type="service" id="event_dispatcher" />

            <tag name="console.command"/>
        </service>

        <!-- Commands -->
        <service id="Shopware\Core\Content\Media\Commands\DeleteThumbnailsCommand">
            <argument type="service" id="Doctrine\DBAL\Connection"/>
            <argument type="service" id="media_thumbnail.repository"/>
            <argument>%shopware.media.remote_thumbnails.enable%</argument>

            <tag name="console.command"/>
        </service>

        <!-- Controller -->
        <service id="Shopware\Core\Content\Media\Api\MediaUploadController" public="true">
            <argument type="service" id="Shopware\Core\Content\Media\MediaService"/>
            <argument type="service" id="Shopware\Core\Content\Media\File\FileSaver"/>
            <argument type="service" id="Shopware\Core\Content\Media\File\FileNameProvider"/>
            <argument type="service" id="Shopware\Core\Content\Media\MediaDefinition"/>
            <argument type="service" id="event_dispatcher"/>

            <call method="setContainer">
                <argument type="service" id="service_container"/>
            </call>
        </service>

        <service id="Shopware\Core\Content\Media\Api\MediaFolderController" public="true">
            <argument type="service" id="Shopware\Core\Content\Media\MediaFolderService"/>
            <call method="setContainer">
                <argument type="service" id="service_container"/>
            </call>
        </service>

        <service id="Shopware\Core\Content\Media\Api\MediaUploadV2Controller" public="true">
            <argument type="service" id="Shopware\Core\Content\Media\Upload\MediaUploadService"/>
        </service>

        <!-- Metadata -->
        <service id="Shopware\Core\Content\Media\Metadata\MetadataLoader\ImageMetadataLoader">
            <tag name="shopware.metadata.loader"/>
        </service>

        <service id="Shopware\Core\Content\Media\Metadata\MetadataLoader">
            <argument type="tagged_iterator" tag="shopware.metadata.loader"/>
        </service>

        <!-- TypeDetector -->
        <service id="Shopware\Core\Content\Media\TypeDetector\AudioTypeDetector">
            <tag name="shopware.media_type.detector" priority="10"/>
        </service>

        <service id="Shopware\Core\Content\Media\TypeDetector\DefaultTypeDetector">
            <tag name="shopware.media_type.detector" priority="0"/>
        </service>

        <service id="Shopware\Core\Content\Media\TypeDetector\DocumentTypeDetector">
            <tag name="shopware.media_type.detector" priority="10"/>
        </service>

        <service id="Shopware\Core\Content\Media\TypeDetector\ImageTypeDetector">
            <tag name="shopware.media_type.detector" priority="10"/>
        </service>

        <service id="Shopware\Core\Content\Media\TypeDetector\VideoTypeDetector">
            <tag name="shopware.media_type.detector" priority="10"/>
        </service>

        <service id="Shopware\Core\Content\Media\TypeDetector\SpatialObjectTypeDetector">
            <tag name="shopware.media_type.detector" priority="10"/>
        </service>

        <service id="Shopware\Core\Content\Media\TypeDetector\TypeDetector">
            <argument type="tagged_iterator" tag="shopware.media_type.detector"/>
        </service>

        <!-- Services -->
        <service id="Shopware\Core\Content\Media\UnusedMediaPurger">
            <argument type="service" id="media.repository"/>
            <argument type="service" id="Doctrine\DBAL\Connection" />
            <argument type="service" id="event_dispatcher"/>
        </service>

        <service id="Shopware\Core\Content\Media\MediaFolderService">
            <argument type="service" id="media.repository"/>
            <argument type="service" id="media_folder.repository"/>
            <argument type="service" id="media_folder_configuration.repository"/>
        </service>

        <service id="Shopware\Core\Content\Media\Thumbnail\ThumbnailService">
            <argument type="service" id="media_thumbnail.repository"/>
            <argument type="service" id="shopware.filesystem.public"/>
            <argument type="service" id="shopware.filesystem.private"/>
            <argument type="service" id="media_folder.repository"/>
            <argument type="service" id="event_dispatcher"/>
            <argument type="service" id="Shopware\Core\Content\Media\DataAbstractionLayer\MediaIndexer"/>
            <argument type="service" id="Shopware\Core\Content\Media\Thumbnail\ThumbnailSizeCalculator"/>
            <argument type="service" id="Doctrine\DBAL\Connection"/>
            <argument>%shopware.media.remote_thumbnails.enable%</argument>
        </service>

        <service id="Shopware\Core\Content\Media\Thumbnail\ThumbnailSizeCalculator">
        </service>

        <service id="Shopware\Core\Content\Media\MediaService">
            <argument type="service" id="media.repository"/>
            <argument type="service" id="media_folder.repository"/>
            <argument type="service" id="Shopware\Core\Content\Media\File\FileLoader"/>
            <argument type="service" id="Shopware\Core\Content\Media\File\FileSaver"/>
            <argument type="service" id="Shopware\Core\Content\Media\File\FileFetcher"/>
        </service>

        <service id="Shopware\Core\Content\Media\Upload\MediaUploadService">
            <argument type="service" id="media.repository"/>
            <argument type="service" id="Shopware\Core\Content\Media\File\FileFetcher"/>
            <argument type="service" id="Shopware\Core\Content\Media\File\FileSaver"/>
            <argument type="service" id="event_dispatcher"/>
            <argument type="service" id="http_client"/>
        </service>

        <service id="Shopware\Core\Content\Media\MediaUrlPlaceholderHandlerInterface" class="Shopware\Core\Content\Media\MediaUrlPlaceholderHandler" public="true">
            <argument type="service" id="Doctrine\DBAL\Connection"/>
            <argument type="service" id="Shopware\Core\Content\Media\Core\Application\AbstractMediaUrlGenerator"/>
        </service>

        <service id="Shopware\Core\Content\Media\Cms\DefaultMediaResolver">
            <argument type="service" id="shopware.filesystem.public"/>
        </service>

        <service id="Shopware\Core\Content\Media\Cms\ImageCmsElementResolver">
            <tag name="shopware.cms.data_resolver" />
            <argument type="service" id="Shopware\Core\Content\Media\Cms\DefaultMediaResolver"/>
        </service>

        <service id="Shopware\Core\Content\Media\Cms\Type\ImageSliderTypeDataResolver">
            <tag name="shopware.cms.data_resolver" />
            <argument type="service" id="Shopware\Core\Content\Media\Cms\DefaultMediaResolver"/>
        </service>

        <service id="Shopware\Core\Content\Media\Cms\Type\ImageGalleryTypeDataResolver">
            <tag name="shopware.cms.data_resolver" />
            <argument type="service" id="Shopware\Core\Content\Media\Cms\DefaultMediaResolver"/>
        </service>

        <service id="Shopware\Core\Content\Media\Cms\YoutubeVideoCmsElementResolver">
            <tag name="shopware.cms.data_resolver" />
        </service>

        <service id="Shopware\Core\Content\Media\Cms\VimeoVideoCmsElementResolver">
            <tag name="shopware.cms.data_resolver" />
        </service>

        <service id="Shopware\Core\Content\Media\DataAbstractionLayer\MediaIndexer">
            <tag name="shopware.entity_indexer"/>
            <argument type="service" id="Shopware\Core\Framework\DataAbstractionLayer\Dbal\Common\IteratorFactory"/>
            <argument type="service" id="media.repository"/>
            <argument type="service" id="media_thumbnail.repository"/>
            <argument type="service" id="Doctrine\DBAL\Connection"/>
            <argument type="service" id="event_dispatcher"/>
            <argument>%shopware.media.remote_thumbnails.enable%</argument>
        </service>

        <service id="Shopware\Core\Content\Media\DataAbstractionLayer\MediaFolderConfigurationIndexer">
            <tag name="shopware.entity_indexer"/>
            <argument type="service" id="Shopware\Core\Framework\DataAbstractionLayer\Dbal\Common\IteratorFactory"/>
            <argument type="service" id="media_folder_configuration.repository"/>
            <argument type="service" id="Doctrine\DBAL\Connection"/>
            <argument type="service" id="event_dispatcher"/>
        </service>

        <service id="Shopware\Core\Content\Media\DataAbstractionLayer\MediaFolderIndexer">
            <argument type="service" id="Shopware\Core\Framework\DataAbstractionLayer\Dbal\Common\IteratorFactory"/>
            <argument type="service" id="media_folder.repository"/>
            <argument type="service" id="Doctrine\DBAL\Connection"/>
            <argument type="service" id="event_dispatcher"/>
            <argument type="service" id="Shopware\Core\Framework\DataAbstractionLayer\Indexing\ChildCountUpdater"/>
            <argument type="service" id="Shopware\Core\Framework\DataAbstractionLayer\Indexing\TreeUpdater"/>

            <tag name="shopware.entity_indexer"/>
        </service>

        <service id="Shopware\Core\Content\Media\Subscriber\MediaDeletionSubscriber">
            <argument type="service" id="event_dispatcher"/>
            <argument type="service" id="media_thumbnail.repository"/>
            <argument type="service" id="messenger.default_bus"/>
            <argument type="service" id="Shopware\Core\Content\Media\Message\DeleteFileHandler"/>
            <argument type="service" id="Doctrine\DBAL\Connection"/>
            <argument type="service" id="media.repository"/>

            <tag name="kernel.event_subscriber"/>
        </service>

        <service id="Shopware\Core\Content\Media\Subscriber\MediaVisibilityRestrictionSubscriber">
            <tag name="kernel.event_subscriber"/>
        </service>

        <service id="Shopware\Core\Content\Media\Subscriber\MediaCreationSubscriber">
            <tag name="kernel.event_subscriber"/>
        </service>

        <service id="Shopware\Core\Content\Media\Subscriber\CustomFieldsUnusedMediaSubscriber">
            <argument type="service" id="Doctrine\DBAL\Connection"/>
            <argument type="service" id="Shopware\Core\Framework\DataAbstractionLayer\DefinitionInstanceRegistry"/>

            <tag name="kernel.event_subscriber"/>
        </service>

        <service id="Shopware\Core\Content\Media\SalesChannel\MediaRoute" public="true">
            <argument type="service" id="media.repository"/>
        </service>
    </services>
</container>
