<?xml version="1.0"?>
<!--
/**
 * @author Amasty Team
 * @copyright Copyright (c) 2023 Amasty (https://www.amasty.com)
 * @package Shipping Table Rates for Magento 2
 */-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Quote\Model\Cart\ShippingMethodConverter">
        <plugin name="amstrates-cart-comment"
                type="Amasty\ShippingTableRates\Model\Cart\ShippingMethodConverter"/>
    </type>

    <type name="Magento\ImportExport\Block\Adminhtml\Import\Edit\Form">
        <plugin name="amstrates-import-edit"
                type="Amasty\ShippingTableRates\Plugin\ImportExport\Block\Adminhtml\Import\Edit\Form"/>
    </type>

    <type name="Magento\ImportExport\Model\Import\SampleFileProvider">
        <arguments>
            <argument name="samples" xsi:type="array">
                <item name="amstrates_rate_import" xsi:type="string">Amasty_ShippingTableRates</item>
            </argument>
        </arguments>
    </type>

    <preference for="Amasty\ShippingTableRates\Api\Data\ShippingTableRateInterface"
                type="Amasty\ShippingTableRates\Model\Rate"/>
    <preference for="Amasty\ShippingTableRates\Api\RateRepositoryInterface"
                type="Amasty\ShippingTableRates\Model\RateRepository"/>
    <preference for="Amasty\ShippingTableRates\Model\Quote\Inventory\QuoteSourceSelectionResultInterface"
                type="Amasty\ShippingTableRates\Model\Quote\Inventory\QuoteSourceSelectionResult" />
    <type name="Magento\Shipping\Model\Rate\CarrierResult">
        <plugin name="Amasty_ShippingTableRates::SortRates" type="Amasty\ShippingTableRates\Plugin\Shipping\Model\Rate\CarrierResultPlugin"/>
    </type>

    <type name="Magento\Shipping\Model\Rate\Result">
        <plugin name="Amasty_ShippingTableRates::SortRates" type="Amasty\ShippingTableRates\Plugin\Shipping\Model\Rate\CarrierResultPlugin"/>
    </type>
    <type name="Amasty\ShippingTableRates\Model\Rate\Provider">
        <arguments>
            <argument name="quoteSession" xsi:type="object">Magento\Checkout\Model\Session</argument>
        </arguments>
    </type>

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

    <virtualType name="Amasty\ShippingTableRates\Model\ResourceModel\Method\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
        <arguments>
            <argument name="mainTable" xsi:type="string">amasty_table_method</argument>
            <argument name="resourceModel" xsi:type="string">Amasty\ShippingTableRates\Model\ResourceModel\Method</argument>
        </arguments>
    </virtualType>
</config>
