<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <!-- Main capture point: SetDataToLegacyStockItem is used by all custom stock crons -->
    <type name="Magento\InventoryCatalog\Model\ResourceModel\SetDataToLegacyStockItem">
        <plugin name="autogedal_stocklog_capture" type="Autogedal\StockLog\Plugin\SetDataToLegacyStockItemPlugin"/>
    </type>

    <!-- Firebear import path: uses MagentoStockItemImporter::import() with direct insertOnDuplicate -->
    <type name="Magento\CatalogImportExport\Model\StockItemImporter">
        <plugin name="autogedal_stocklog_importer_capture" type="Autogedal\StockLog\Plugin\StockItemImporterPlugin"/>
    </type>

    <!-- Source attribution: virtual types wrap each cron's execute() without touching cron files -->
    <virtualType name="AutogedalStockLogPtcPlugin" type="Autogedal\StockLog\Plugin\Cron\SetSourcePlugin">
        <arguments>
            <argument name="source" xsi:type="string">cron_ptc</argument>
        </arguments>
    </virtualType>
    <type name="Leadlion\StockUpdates\Cron\PtcStock">
        <plugin name="autogedal_stocklog_set_source" type="AutogedalStockLogPtcPlugin"/>
    </type>

    <virtualType name="AutogedalStockLogPtcLaComandaPlugin" type="Autogedal\StockLog\Plugin\Cron\SetSourcePlugin">
        <arguments>
            <argument name="source" xsi:type="string">cron_ptc_la_comanda</argument>
        </arguments>
    </virtualType>
    <type name="Leadlion\StockUpdates\Cron\PtcLaComanda">
        <plugin name="autogedal_stocklog_set_source" type="AutogedalStockLogPtcLaComandaPlugin"/>
    </type>

    <virtualType name="AutogedalStockLogCarsupremePlugin" type="Autogedal\StockLog\Plugin\Cron\SetSourcePlugin">
        <arguments>
            <argument name="source" xsi:type="string">cron_carsupreme</argument>
        </arguments>
    </virtualType>
    <type name="Leadlion\StockUpdates\Cron\CarsupremeStock">
        <plugin name="autogedal_stocklog_set_source" type="AutogedalStockLogCarsupremePlugin"/>
    </type>

    <virtualType name="AutogedalStockLogAlfaromtransPlugin" type="Autogedal\StockLog\Plugin\Cron\SetSourcePlugin">
        <arguments>
            <argument name="source" xsi:type="string">cron_alfaromtrans</argument>
        </arguments>
    </virtualType>
    <type name="Leadlion\StockUpdates\Cron\AlfaromtransStock">
        <plugin name="autogedal_stocklog_set_source" type="AutogedalStockLogAlfaromtransPlugin"/>
    </type>

    <virtualType name="AutogedalStockLogSmartbillPlugin" type="Autogedal\StockLog\Plugin\Cron\SetSourcePlugin">
        <arguments>
            <argument name="source" xsi:type="string">cron_smartbill</argument>
        </arguments>
    </virtualType>
    <type name="Leadlion\StockUpdates\Cron\Stocks">
        <plugin name="autogedal_stocklog_set_source" type="AutogedalStockLogSmartbillPlugin"/>
    </type>

    <virtualType name="AutogedalStockLogFeedOosPlugin" type="Autogedal\StockLog\Plugin\Cron\SetSourcePlugin">
        <arguments>
            <argument name="source" xsi:type="string">cron_feed_oos</argument>
        </arguments>
    </virtualType>
    <type name="Leadlion\Autogedal\Cron\FeedOosProducts">
        <plugin name="autogedal_stocklog_set_source" type="AutogedalStockLogFeedOosPlugin"/>
    </type>

    <!-- Grid data provider virtual types -->
    <virtualType name="AutogedalStockLogGridFilterPool" type="Magento\Framework\View\Element\UiComponent\DataProvider\FilterPool">
        <arguments>
            <argument name="appliers" xsi:type="array">
                <item name="regular" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\RegularFilter</item>
                <item name="fulltext" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilter</item>
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="AutogedalStockLogGridDataProvider" type="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider">
        <arguments>
            <argument name="collection" xsi:type="object" shared="false">Autogedal\StockLog\Model\ResourceModel\StockLog\Grid\Collection</argument>
            <argument name="filterPool" xsi:type="object" shared="false">AutogedalStockLogGridFilterPool</argument>
        </arguments>
    </virtualType>
    <virtualType name="AutogedalStockLogArchiveGridDataProvider" type="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider">
        <arguments>
            <argument name="collection" xsi:type="object" shared="false">Autogedal\StockLog\Model\ResourceModel\StockLog\Archive\Grid\Collection</argument>
            <argument name="filterPool" xsi:type="object" shared="false">AutogedalStockLogGridFilterPool</argument>
        </arguments>
    </virtualType>
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="autogedal_stocklog_listing_data_source" xsi:type="string">Autogedal\StockLog\Model\ResourceModel\StockLog\Grid\Collection</item>
                <item name="autogedal_stocklog_archive_listing_data_source" xsi:type="string">Autogedal\StockLog\Model\ResourceModel\StockLog\Archive\Grid\Collection</item>
            </argument>
        </arguments>
    </type>

</config>
