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

    <preference for="Magento\Rma\Api\Data\RmaExtensionInterface" type="Magento\Rma\Api\Data\RmaExtension" />
    <preference for="FiloBlu\Rma\Api\RmaExtensionAttributesRepositoryInterface" type="FiloBlu\Rma\Model\Rma\RmaExtensionAttributesRepository"/>
    <preference for="FiloBlu\Rma\Api\EasyReturnRepositoryInterface" type="FiloBlu\Rma\Model\EasyReturnRepository"/>
    <preference for="FiloBlu\Rma\Api\Data\EasyReturnInterface" type="FiloBlu\Rma\Model\EasyReturn"/>
    <preference for="FiloBlu\Rma\Api\ChangeSizeRepositoryInterface" type="FiloBlu\Rma\Model\ChangeSizeRepository"/>
    <preference for="FiloBlu\Rma\Api\ChangeSizeInterface" type="FiloBlu\Rma\Model\ChangeSize"/>
    <preference for="Magento\Rma\Block\Returns\Create" type="FiloBlu\Rma\Block\Returns\Create"/>
    <preference for="FiloBlu\Rma\Api\RmaManagementInterface" type="FiloBlu\Rma\Model\RmaManagement"/>
    <preference for="FiloBlu\Rma\Api\RmaItemResolutionHistoryInterface" type="FiloBlu\Rma\Model\RmaItemResolutionHistoryRepository"/>
    <preference for="Magento\Sales\Model\Order\Payment" type="FiloBlu\Rma\Model\Order\Payment" />
    <preference for="Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Items" type="FiloBlu\Rma\Block\Adminhtml\Order\Creditmemo\Create\Items" />
    <preference for="FiloBlu\Rma\Api\Data\RmaAttributeMetadataInterface" type="FiloBlu\Rma\Model\RmaAttributeMetadata" />
    <preference for="FiloBlu\Rma\Api\Data\RmaOptionInterface" type="FiloBlu\Rma\Model\RmaOption"/>

    <!-- EASY RETURN -->
    <virtualType name="FiloBlu\Rma\Model\ResourceModel\Carrier\EasyReturnRate" type="FiloBlu\Rma\Model\ResourceModel\Carrier\Rate">
        <arguments>
            <argument name="matrixRateSource" xsi:type="string">easy_return</argument>
        </arguments>
    </virtualType>

    <virtualType name="FiloBlu\Rma\Model\ResourceModel\Carrier\EasyReturnRateFactory" type="FiloBlu\Rma\Model\ResourceModel\Carrier\RateFactory">
        <arguments>
            <argument name="instanceName" xsi:type="string">FiloBlu\Rma\Model\ResourceModel\Carrier\EasyReturnRate</argument>
        </arguments>
    </virtualType>

    <virtualType name="FiloBlu\Rma\Model\Carrier\EasyReturnRate" type="FiloBlu\Rma\Model\Carrier\CarrierRate">
        <arguments>
            <argument name="rateFactory" xsi:type="object">FiloBlu\Rma\Model\ResourceModel\Carrier\EasyReturnRateFactory</argument>
            <argument name="code" xsi:type="string">easy_return_matrixrate</argument>
            <argument name="defaultConditionName" xsi:type="string">package_weight</argument>
            <argument name="carrierName" xsi:type="string">matrixrate</argument>
            <argument name="matrixRateSource" xsi:type="string">filoblu_easy_return_matrixrate</argument>
        </arguments>
    </virtualType>

    <virtualType name="FiloBlu\Rma\Model\Carrier\EasyReturnCarrierRateFactory" type="FiloBlu\Rma\Model\Carrier\CarrierRateFactory">
        <arguments>
            <argument name="instanceName" xsi:type="string">FiloBlu\Rma\Model\Carrier\EasyReturnRate</argument>
        </arguments>
    </virtualType>

    <!-- CHANGE SIZE -->
    <virtualType name="FiloBlu\Rma\Model\ResourceModel\Carrier\ChangeSizeRate" type="FiloBlu\Rma\Model\ResourceModel\Carrier\Rate">
        <arguments>
            <argument name="rate" xsi:type="object">FiloBlu\Rma\Model\Carrier\ChangeSizeRate</argument>
            <argument name="matrixRateSource" xsi:type="string">change_size</argument>
        </arguments>
    </virtualType>

    <virtualType name="FiloBlu\Rma\Model\ResourceModel\Carrier\ChangeSizeRateFactory" type="FiloBlu\Rma\Model\ResourceModel\Carrier\RateFactory">
        <arguments>
            <argument name="instanceName" xsi:type="string">FiloBlu\Rma\Model\ResourceModel\Carrier\ChangeSizeRate</argument>
        </arguments>
    </virtualType>

    <virtualType name="FiloBlu\Rma\Model\Carrier\ChangeSizeRate" type="FiloBlu\Rma\Model\Carrier\CarrierRate">
        <arguments>
            <argument name="rateFactory" xsi:type="object">FiloBlu\Rma\Model\ResourceModel\Carrier\ChangeSizeRateFactory</argument>
            <argument name="code" xsi:type="string">change_size_matrixrate</argument>
            <argument name="defaultConditionName" xsi:type="string">package_weight</argument>
            <argument name="carrierName" xsi:type="string">change_size</argument>
            <argument name="matrixRateSource" xsi:type="string">filoblu_change_size_matrixrate</argument>
        </arguments>
    </virtualType>

    <virtualType name="FiloBlu\Rma\Model\Carrier\ChangeSizeCarrierRateFactory" type="FiloBlu\Rma\Model\Carrier\CarrierRateFactory">
        <arguments>
            <argument name="instanceName" xsi:type="string">FiloBlu\Rma\Model\Carrier\ChangeSizeRate</argument>
        </arguments>
    </virtualType>

    <type name="Magento\Rma\Model\Rma">
        <plugin name="FiloBlu_Rma_Model_Fix_Bundle_Rma_Items" type="FiloBlu\Rma\Plugin\Model\FixBundleRmaItems" sortOrder="10"/>
        <plugin name="FiloBlu_Rma_Model_Rma_Processor" type="FiloBlu\Rma\Plugin\Model\RmaModelRmaProcessor" sortOrder="20"/>
    </type>

    <type name="Magento\Rma\Api\RmaRepositoryInterface">
        <plugin name="FiloBlu_Rma_Managment_Rma_Processor" type="FiloBlu\Rma\Plugin\Model\Service\RmaManagmentProcessor"/>
        <plugin name="filoblu_extrma_after_get" type="FiloBlu\Rma\Plugin\Rma\Api\RmaRepositoryInterface\AfterGet" sortOrder="1"/>
    </type>

    <type name="FiloBlu\Rma\Api\Model\Config\Reader">
        <arguments>
            <argument name="fileName" xsi:type="string">rma_reasons.xml</argument>
            <argument name="converter" xsi:type="object">FiloBlu\Rma\Api\Model\Config\Converter</argument>
            <argument name="schemaLocator" xsi:type="object">FiloBlu\Rma\Api\Model\Config\SchemaLocator</argument>
        </arguments>
    </type>

    <type name="Magento\Rma\Block\Form\Renderer\Select">
        <plugin name="FiloBlu_Rma_Block_Form_Renderer_Select" type="FiloBlu\Rma\Plugin\Block\Form\Renderer\Select"/>
    </type>

    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="filoblu_rma_rma_listing_data_source" xsi:type="string">FiloBlu\Rma\Model\ResourceModel\RmaGrid\Grid\Collection</item>
            </argument>
        </arguments>
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="filoblu_rma_rmaitemresolutionhistory_data_source" xsi:type="string">FiloBlu\Rma\Model\ResourceModel\RmaItemResolutionHistory\Grid\Collection</item>
            </argument>
        </arguments>
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="filoblu_change_size_items_listing_data_source" xsi:type="string">FiloBlu\Rma\Model\ResourceModel\ChangeSizeItems\Grid\Collection</item>
            </argument>
        </arguments>
    </type>

    <type name="FiloBlu\Rma\Model\ResourceModel\RmaGrid\Grid\Collection">
        <arguments>
            <argument name="mainTable" xsi:type="string">magento_rma_status_history</argument>
            <argument name="resourceModel" xsi:type="string">FiloBlu\Rma\Model\ResourceModel\RmaGrid</argument>
            <argument name="eventPrefix" xsi:type="string">filoblu_rma_rma_grid_collection</argument>
            <argument name="eventObject" xsi:type="string">filoblu_rma_rma_collection</argument>
        </arguments>
    </type>

    <type name="Magento\Rma\Helper\Data">
        <plugin name="FiloBlu_Rma_Helper_Data_Processor" type="FiloBlu\Rma\Plugin\Helper\RmaHelperDataProcessor" sortOrder="1" disabled="false" />
    </type>

    <type name="Magento\Rma\Controller\Returns\Create">
        <plugin name="disable_personalized_order_rma" type="FiloBlu\Rma\Plugin\ShowCustomErrorMessageForRma" sortOrder="1" disabled="false" />
        <plugin name="mod2_extrma_validate_around_execute" type="FiloBlu\Rma\Plugin\Returns\Create"/>
    </type>

    <type name="Magento\Rma\Helper\Eav">
        <plugin name="hide_change_size_resolution" type="FiloBlu\Rma\Plugin\Model\HideChangeSizeResolution" sortOrder="1"/>
    </type>

    <type name="Magento\Rma\Model\Rma\RmaDataMapper">
        <plugin name="save_change_size_answer" type="FiloBlu\Rma\Plugin\Model\Rma\RmaDataMapper" sortOrder="1"/>
    </type>

    <type name="Magento\Framework\Console\CommandList">
        <arguments>
            <argument name="commands" xsi:type="array">
                <item name="sync_changesize_order" xsi:type="object">FiloBlu\Rma\Console\SyncChangeSizeOrder</item>
                <item name="restore_missing_rma" xsi:type="object">FiloBlu\Rma\Console\RestoreOrderRma</item>
                <item name="regenerate_cs_orders" xsi:type="object">FiloBlu\Rma\Console\GenerateMissingChangeSizeOrders</item>
                <item name="regenerate_easyreturn_data" xsi:type="object">FiloBlu\Rma\Console\GenerateMissingEasyReturnData</item>
            </argument>
        </arguments>
    </type>

    <type name="Magento\Config\Model\Config\Source\Email\Template">
        <plugin name="filobluRmaConfigModelConfigSourceEmailTemplate" type="FiloBlu\Rma\Plugin\EmailTemplate" sortOrder="1"/>
    </type>

    <type name="Magento\Sales\Model\Order\Email\Sender\OrderSender">
        <plugin name="filoblu_extrma_changesize_order_email_sender" type="FiloBlu\Rma\Plugin\Model\Order\Email\OrderSender" sortOrder="1"/>
    </type>

    <type name="Magento\Sales\Api\OrderRepositoryInterface">
        <plugin name="mod2_extrma_add_order_additional_data" type="FiloBlu\Rma\Plugin\OrderGet"/>
        <plugin name="filoblu_check_on_payment_method_to_add_iban_required_for_return" type="FiloBlu\Rma\Plugin\AddIbanRequiredFlagToOrder"/>
    </type>

    <type name="FiloBlu\Rma\Logger\Handler">
        <arguments>
            <argument name="filesystem" xsi:type="object">Magento\Framework\Filesystem\Driver\File</argument>
        </arguments>
    </type>

    <type name="FiloBlu\Rma\Logger\Logger">
        <arguments>
            <argument name="name" xsi:type="string">filoblu_extrma_logger</argument>
            <argument name="handlers"  xsi:type="array">
                <item name="system" xsi:type="object">FiloBlu\Rma\Logger\Handler</item>
            </argument>
        </arguments>
    </type>

    <!-- config exporter -->
    <type name="FiloBlu\Refilo\Model\Exporter\Config">
        <arguments>
            <argument name="providers" xsi:type="array">
                <item name="extrma" xsi:type="object">FiloBlu\Rma\Model\Configuration\ExtrmaConfigProvider</item>
            </argument>
        </arguments>
    </type>

    <type name="FiloBlu\Rma\Console\RestoreOrderRma">
        <arguments>
            <argument name="changeSize" xsi:type="object">FiloBlu\Rma\Model\ChangeSize\Proxy</argument>
        </arguments>
    </type>

    <type name="FiloBlu\Rma\Model\ChangeSize">
        <arguments>
            <argument name="customerSession" xsi:type="object">Magento\Customer\Model\Session\Proxy</argument>
        </arguments>
    </type>

    <type name="FiloBlu\Rma\Block\Adminhtml\System\Config\Policies">
        <arguments>
            <argument name="context" xsi:type="object">\Magento\Backend\Block\Template\Context</argument>
            <argument name="customerGroupCollectionFactory" xsi:type="object">\Magento\Customer\Model\ResourceModel\Group\CollectionFactory</argument>
        </arguments>
    </type>

    <type name="FiloBlu\Rma\Helper\EasyReturnHelper">
        <plugin name="filoblu_extrma_easy_return_helper" type="FiloBlu\Rma\Plugin\EasyReturnHelperPlugin" disabled="false" sortOrder="10" />
        <plugin name="filoblu_extrma_easy_return_helper" type="FiloBlu\Rma\Plugin\EasyReturnHelperPlugin" disabled="false" sortOrder="10" />
        <plugin name="filoblu_extrma_free_return_shipping" type="FiloBlu\Rma\Plugin\SetFreeReturnShipping" disabled="false" sortOrder="20" />
        <arguments>
            <argument name="changeSizeRateFactory" xsi:type="object">FiloBlu\Rma\Model\Carrier\ChangeSizeCarrierRateFactory</argument>
            <argument name="easyReturnRateFactory" xsi:type="object">FiloBlu\Rma\Model\Carrier\EasyReturnCarrierRateFactory</argument>
        </arguments>
    </type>

    <type name="FiloBlu\Rma\Model\OrderLocator" shared="true"/>

    <type name="Adyen\Payment\Helper\Creditmemo">
        <plugin name="FiloBlu_Rma_Helper_Creditmemo_Processor" type="FiloBlu\Rma\Plugin\Helper\RmaHelperCreditmemoProcessor" sortOrder="1" disabled="false" />
    </type>

    <type name="Klarna\Kp\Model\Payment\Kp">
        <plugin name="FiloBlu_Rma_Model_Payment_Kp" type="FiloBlu\Rma\Plugin\Model\Payment\Kp" sortOrder="1" disabled="false" />
    </type>

    <type name="Magento\Sales\Block\Order\Email\Items">
        <plugin name="filoblu_rma_sales_block_order_email_items" type="FiloBlu\Rma\Plugin\Sales\Block\Order\Email\Items" sortOrder="10" disabled="false" />
    </type>

    <type name="Magento\Sales\Block\Order\Totals">
        <plugin name="filoblu_rma_sales_block_order_totals" type="FiloBlu\Rma\Plugin\Sales\Block\Order\Totals" sortOrder="10" disabled="false" />
    </type>

    <type name="FiloBlu\Rma\Block\Returns\Create">
        <plugin name="filoblu_extrma_block_return-create" type="FiloBlu\Rma\Plugin\Rma\Block\Returns\Create" disabled="false" sortOrder="10" />
    </type>

    <type name="FiloBlu\Rma\Model\Payment\ChangeSizePay">
        <arguments>
            <argument name="paymentData" xsi:type="object">Magento\Payment\Helper\Data\Proxy</argument>
        </arguments>
    </type>

    <type name="Magento\Rma\Model\Item">
        <plugin name="filoblu_extrma_rme_mode_item_plugin" type="FiloBlu\Rma\Plugin\Model\Rma\Item" sortOrder="10" disabled="false"/>
    </type>

    <type name="Magento\Rma\Model\Service\RmaAttributesManagement">
        <plugin name="filoblu_extrma_fix_attribute_get_all_attributes_metadata" type="FiloBlu\Rma\Plugin\Rma\Model\Service\RmaAttributesManagement" disabled="false" sortOrder="10" />
     </type>

    <type name="FiloBlu\Rma\Model\ResourceModel\RmaItemResolutionHistory\Grid\Collection">
        <arguments>
            <argument name="mainTable" xsi:type="string">filoblu_rma_items_resolution_history</argument>
            <argument name="resourceModel" xsi:type="string">FiloBlu\Rma\Model\RmaItemResolutionHistory\RmaGrid</argument>
            <argument name="eventPrefix" xsi:type="string">filoblu_rma_items_resolution_history_collection</argument>
            <argument name="eventObject" xsi:type="string">filoblu_rma_resolution_history_collection</argument>
        </arguments>
    </type>

    <type name="FiloBlu\Rma\Model\ResourceModel\ChangeSizeItems\Grid\Collection">
        <arguments>
            <argument name="mainTable" xsi:type="string">filoblu_change_size_items</argument>
            <argument name="resourceModel" xsi:type="string">FiloBlu\Rma\Model\ChangeSizeItems</argument>
            <argument name="eventPrefix" xsi:type="string">filoblu_rma_change_size_items_collection</argument>
            <argument name="eventObject" xsi:type="string">filoblu_rma_change_size_items_collection</argument>
        </arguments>
    </type>

    <type name="FiloBlu\Rma\Block\Adminhtml\Carrier\Matrixrate\EasyReturnGrid">
        <arguments>
            <argument name="matrixRate" xsi:type="object">FiloBlu\Rma\Model\Carrier\EasyReturnRate</argument>
        </arguments>
    </type>

    <type name="FiloBlu\Rma\Model\Config\Backend\EasyReturnRate">
        <arguments>
            <argument name="easyReturnRateFactory" xsi:type="object">FiloBlu\Rma\Model\ResourceModel\Carrier\EasyReturnRateFactory</argument>
        </arguments>
    </type>

    <type name="FiloBlu\Rma\Helper\ChangeSizeHelper">
        <arguments>
            <argument name="easyReturnRateFactory" xsi:type="object">FiloBlu\Rma\Model\ResourceModel\Carrier\EasyReturnRateFactory</argument>
        </arguments>
    </type>

    <type name="Magento\Rma\Model\Rma\Status\History">
        <plugin name="FiloBlu_Rma_Model_Rma_Status_History" type="FiloBlu\Rma\Plugin\Model\Rma\Status\History"/>
    </type>

    <!-- EFFCNT-128 | RMA con Multibanco e contrassegno: Inserimento campo IBAN su form RMA -->
    <!-- Map here other payment methods to require IBAN during return creation -->
    <type name="FiloBlu\Rma\Model\Config\Source\OfflinePaymentMethodsProvider">
        <arguments>
            <argument name="offlinePaymentMethods" xsi:type="array">
                <item name="adyen_hpp" xsi:type="array">
                    <item name="value" xsi:type="string">adyen_hpp</item>
                    <item name="label" xsi:type="string">Adyen Alternative payment methods</item>
                </item>
                <item name="adyen_multibanco" xsi:type="array">
                    <item name="value" xsi:type="string">adyen_multibanco</item>
                    <item name="label" xsi:type="string">Adyen Multibanco</item>
                </item>
                <item name="adyen_bankTransfer_IBAN" xsi:type="array">
                    <item name="value" xsi:type="string">adyen_bankTransfer_IBAN</item>
                    <item name="label" xsi:type="string">Adyen Bank Transfer IBAN</item>
                </item>
                <item name="msp_cashondelivery" xsi:type="array">
                    <item name="value" xsi:type="string">msp_cashondelivery</item>
                    <item name="label" xsi:type="string">Msp Cash on delivery</item>
                </item>
            </argument>
        </arguments>
    </type>

    <type name="Magento\Sales\Model\Order\Email\Sender\CreditmemoSender">
        <plugin name="filoblu_rma_plugin_manage_sending_credit_memo_mail" type="FiloBlu\Rma\Plugin\Sales\Model\CreditMemoSenderManager"/>
    </type>

    <type name="Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Save">
        <plugin name="filoblu_rma_plugin_force_creditmemo_email_sending" type="FiloBlu\Rma\Plugin\Sales\Controller\Adminhtml\Order\Creditmemo\Save"/>
    </type>

    <virtualType name="FiloBlu\Rma\Model\TheoricShippingAmountFactory" type="Magento\Framework\DataObject\Factory" />

    <type name="FiloBlu\Rma\Model\EasyReturn">
        <arguments>
            <argument name="theoricShippingAmountFactory" xsi:type="object">FiloBlu\Rma\Model\TheoricShippingAmountFactory</argument>
        </arguments>
    </type>

    <type name="Magento\Sales\Model\Order\ShipmentDocumentFactory">
        <arguments>
            <argument name="shipmentFactory" xsi:type="object">FiloBlu\Rma\Model\Order\ShipmentFactory</argument>
        </arguments>
    </type>

    <type name="Magento\OfflineShipping\Model\Carrier\Tablerate">
        <plugin name="filoblu_rma_plugin_offline_shipping_model_carrier_tablerate" type="FiloBlu\Rma\Plugin\OfflineShipping\Model\Carrier\TableRate"/>
    </type>

    <type name="Magento\Sales\Model\Order\Item">
        <plugin name="filoblu_rma_plugin_order_item_is_dummy" type="FiloBlu\Rma\Plugin\Sales\Model\Order\ItemIsDummy"/>
    </type>

</config>
