<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\ProductAlert\Model\ResourceModel\Stock\Customer\Collection"
                type="Amasty\Xnotif\Model\ResourceModel\Stock\Customer\Collection"/>
    <preference for="Magento\ProductAlert\Model\ResourceModel\Price\Customer\Collection"
                type="Amasty\Xnotif\Model\ResourceModel\Price\Customer\Collection"/>

    <preference for="Magento\ProductAlert\Model\Observer" type="Amasty\Xnotif\Model\Observer"/>

    <preference for="Magento\Bundle\Model\ResourceModel\Selection\Collection"
                type="Amasty\Xnotif\Model\ResourceModel\Bundle\Selection\Collection"/>

    <!-- fix grouped problem issue -->
    <preference for="Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection"
                type="Amasty\Xnotif\Model\ResourceModel\Product\Link\Product\Collection"/>

    <type name="Magento\CatalogInventory\Observer\SubtractQuoteInventoryObserver">
        <plugin name="Amasty_Xnotif::low-stock-alert" type="Amasty\Xnotif\Plugins\CatalogInventory\Observer\LowStockAlert"/>
    </type>

    <type name="Magento\Framework\Mail\Template\TransportBuilder">
        <plugin name="Amasty_Xnotif::fix_store_email" type="Amasty\Xnotif\Plugins\Mail\Template\TransportBuilder"/>
    </type>

    <!-- change unsubscribe url - add params start-->
    <type name="Magento\ProductAlert\Block\Email\Price">
        <plugin name="Amasty_Xnotif::GetUnsubscribeUrlPrice" type="Amasty\Xnotif\Plugins\ProductAlert\Block\Email\Url"/>
    </type>

    <type name="Magento\ProductAlert\Block\Email\Stock">
        <plugin name="Amasty_Xnotif::GetUnsubscribeUrlStock" type="Amasty\Xnotif\Plugins\ProductAlert\Block\Email\Url"/>
    </type>
    <!-- change unsubscribe url - add params end-->

    <type name="Amasty\Xnotif\Model\Analytics\Request\Daily\Stock">
        <arguments>
            <argument name="data" xsi:type="array">
                <item name="dateTime" xsi:type="object">Magento\Framework\Stdlib\DateTime\DateTime</item>
                <item name="resourceModel" xsi:type="object">Amasty\Xnotif\Model\ResourceModel\Analytics\Request\Daily\Stock</item>
            </argument>
        </arguments>
    </type>
    <preference for="Amasty\Xnotif\Api\Analytics\Data\Daily\StockInterface" type="Amasty\Xnotif\Model\Analytics\Request\Daily\Stock" />
    <preference for="Amasty\Xnotif\Api\Analytics\Daily\StockRepositoryInterface" type="Amasty\Xnotif\Model\Repository\Analytics\Daily\StockRepository" />
    <preference for="Amasty\Xnotif\Api\Analytics\Data\StockInterface" type="Amasty\Xnotif\Model\Analytics\Request\Stock" />
    <preference for="Amasty\Xnotif\Api\Analytics\StockRepositoryInterface" type="Amasty\Xnotif\Model\Repository\Analytics\StockRepository" />

    <type name="Magento\ProductAlert\Block\Product\ImageProvider">
        <plugin name="Amasty_Xnotif::fix-emulate-error" type="Amasty\Xnotif\Plugins\ProductAlert\Block\Product\ImageProvider"/>
    </type>

    <!-- fix magento bug with implimenting post interface -->
    <preference for="Magento\ProductAlert\Controller\Unsubscribe\Stock" type="Amasty\Xnotif\Controller\Unsubscribe\Stock" />

    <type name="Amasty\Gdpr\Model\Source\CheckboxLocationCombine">
        <arguments>
            <argument name="optionGroups" xsi:type="array">
                <item name="amasty" xsi:type="array">
                    <item name="optionSources" xsi:type="array">
                        <item name="amxnotif" xsi:type="object">Amasty\Xnotif\Model\Config\GdprXnotif</item>
                    </item>
                </item>
            </argument>
        </arguments>
    </type>

    <type name="Amasty\Gdpr\ViewModel\Adminhtml\System\Config\GdprCommentViewModel">
        <arguments>
            <argument name="sectionComments" xsi:type="array">
                <item name="amxnotif" xsi:type="array">
                    <item name="selector" xsi:type="string">#row_amxnotif_gdrp_enabled</item>
                    <item name="comment" xsi:type="string" translate="true"><![CDATA[Please disable the setting if you use consent checkboxes configured for Out of Stock Notification forms via <a href='%1'>GDPR Consent Checkboxes.</a>]]></item>
                </item>
            </argument>
        </arguments>
    </type>

    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="xnotif_subscription_listing_data_source"
                      xsi:type="string">Amasty\Xnotif\Model\ResourceModel\Stock\Subscription\Grid\Collection</item>
            </argument>
        </arguments>
    </type>

    <type name="Amasty\Xnotif\Model\ResourceModel\Stock\Subscription\Grid\Collection">
        <arguments>
            <argument name="mainTable" xsi:type="string">product_alert_stock</argument>
            <argument name="resourceModel" xsi:type="string">Magento\ProductAlert\Model\ResourceModel\Stock</argument>
        </arguments>
    </type>
</config>
