<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <!-- Virtual type -->
    <virtualType name="Magento\Framework\Pricing\Price\Pool">
        <arguments>
            <argument name="prices" xsi:type="array">
                <item name="installment_price" xsi:type="string">Leanpay\Payment\Pricing\Price\Installment</item>
            </argument>
        </arguments>
    </virtualType>

    <virtualType name="Leanpay\Payment\Model\Api\SearchCriteria\CollectionProcessor\InstallmentProductFilterProcessor"
                 type="Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor">
        <arguments>
            <argument name="customFilters" xsi:type="array">
                <item name="store_id" xsi:type="object">
                    Leanpay\Payment\Api\SearchCriteria\CollectionProcessor\FilterProcessor\InstallmentProductStoreFilter
                </item>
            </argument>
        </arguments>
    </virtualType>

    <virtualType name="Leanpay\Payment\Model\Api\SearchCriteria\CollectionProcessor\InstallmentFilterProcessor"
                 type="Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor">
        <arguments>
            <argument name="customFilters" xsi:type="array">
                <item name="store_id" xsi:type="object">
                    Leanpay\Payment\Api\SearchCriteria\CollectionProcessor\FilterProcessor\InstallmentProductStoreFilter
                </item>
            </argument>
        </arguments>
    </virtualType>

    <virtualType name="Leanpay\Payment\Model\Api\SearchCriteria\InstallmentCollectionProcessor"
                 type="Magento\Framework\Api\SearchCriteria\CollectionProcessor">
        <arguments>
            <argument name="processors" xsi:type="array">
                <item name="filters" xsi:type="object">
                    Leanpay\Payment\Model\Api\SearchCriteria\CollectionProcessor\InstallmentFilterProcessor
                </item>
                <item name="sorting" xsi:type="object">
                    Magento\Framework\Api\SearchCriteria\CollectionProcessor\SortingProcessor
                </item>
                <item name="pagination" xsi:type="object">
                    Magento\Framework\Api\SearchCriteria\CollectionProcessor\PaginationProcessor
                </item>
            </argument>
        </arguments>
    </virtualType>

    <virtualType name="Leanpay\Payment\Model\Api\SearchCriteria\InstallmentProductCollectionProcessor"
                 type="Magento\Framework\Api\SearchCriteria\CollectionProcessor">
        <arguments>
            <argument name="processors" xsi:type="array">
                <item name="filters" xsi:type="object">
                    Leanpay\Payment\Model\Api\SearchCriteria\CollectionProcessor\InstallmentProductFilterProcessor
                </item>
                <item name="sorting" xsi:type="object">
                    Magento\Framework\Api\SearchCriteria\CollectionProcessor\SortingProcessor
                </item>
                <item name="pagination" xsi:type="object">
                    Magento\Framework\Api\SearchCriteria\CollectionProcessor\PaginationProcessor
                </item>
            </argument>
        </arguments>
    </virtualType>

    <!-- DI Injections -->
    <type name="Leanpay\Payment\Logger\Handler">
        <arguments>
            <argument name="filesystem" xsi:type="object">Magento\Framework\Filesystem\Driver\File</argument>
        </arguments>
    </type>

    <type name="Leanpay\Payment\Logger\PaymentLogger">
        <arguments>
            <argument name="name" xsi:type="string">leanpay</argument>
            <argument name="handlers" xsi:type="array">
                <item name="system" xsi:type="object">Leanpay\Payment\Logger\Handler</item>
            </argument>
        </arguments>
    </type>

    <!-- Plugins -->
    <type name="Magento\Catalog\Block\Product\View">
        <plugin name="LeanpayInstallmentViewPlugin" type="Leanpay\Payment\Plugin\Block\Product\View\ViewPlugin" sortOrder="10"/>
    </type>
    <type name="Magento\Payment\Model\Checks\TotalMinMax">
        <plugin name="TotalMinMaxLeanpay" type="Leanpay\Payment\Plugin\TotalMinMaxPlugin" sortOrder="1"/>
    </type>

    <type name="Magento\Payment\Model\Checks\CanUseForCountry">
        <plugin name="CanUseForCountryLeanpay" type="Leanpay\Payment\Plugin\CanUseForCountryPlugin" sortOrder="1"/>
    </type>

    <type name="Magento\Framework\App\Request\CsrfValidator">
        <plugin name="csrf_validator_skip" type="Leanpay\Payment\Plugin\CsrfValidatorSkip"/>
    </type>

    <!-- Preferences -->
    <preference for="Leanpay\Payment\Api\Data\InstallmentInterface" type="Leanpay\Payment\Model\Installment"/>
    <preference for="Leanpay\Payment\Api\InstallmentRepositoryInterface"
                type="Leanpay\Payment\Model\InstallmentRepository"/>
    <preference for="Leanpay\Payment\Api\Data\InstallmentProductInterface"
                type="Leanpay\Payment\Model\InstallmentProduct"/>
    <preference for="Leanpay\Payment\Api\InstallmentProductRepositoryInterface"
                type="Leanpay\Payment\Model\InstallmentProductRepository"/>
    <preference for="Leanpay\Payment\Api\Data\InstallmentProductSearchResultsInterface"
                type="Leanpay\Payment\Model\InstallmentProductSearchResults"/>
    <preference for="Leanpay\Payment\Api\Data\InstallmentSearchResultsInterface"
                type="Leanpay\Payment\Model\InstallmentSearchResults"/>
    <preference for="Leanpay\Payment\Api\RequestInterface" type="Leanpay\Payment\Model\Request"/>

    <!-- Comand line -->
    <type name="Magento\Framework\Console\CommandList">
        <arguments>
            <argument name="commands" xsi:type="array">
                <item name="import" xsi:type="object">Leanpay\Payment\Console\Import</item>
                <item name="promotions" xsi:type="object">Leanpay\Payment\Console\RemoveExpiredPromotionsCommand</item>
            </argument>
        </arguments>
    </type>
</config>
