<?xml version="1.0"?>
<!--
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <!-- Payment Method Facade configuration -->
    <virtualType name="SmartRouteFacade" type="Magento\Payment\Model\Method\Adapter">
        <arguments>
            <argument name="code" xsi:type="const">\Sts\SmartRoute\Model\Ui\ConfigProvider::CODE</argument>
            <argument name="formBlockType" xsi:type="string">Magento\Payment\Block\Form</argument>
            <argument name="infoBlockType" xsi:type="string">Sts\SmartRoute\Block\Info</argument>
            <argument name="valueHandlerPool" xsi:type="object">SmartRouteValueHandlerPool</argument>
            <argument name="commandPool" xsi:type="object">SmartRouteCommandPool</argument>
        </arguments>
    </virtualType>

    <!-- Configuration reader -->
    <virtualType name="SmartRouteConfig" type="Magento\Payment\Gateway\Config\Config">
        <arguments>
            <argument name="methodCode" xsi:type="const">\Sts\SmartRoute\Model\Ui\ConfigProvider::CODE</argument>
        </arguments>
    </virtualType>

    <!-- Logger, initialized with SmartRouteConfig -->
    <virtualType name="SmartRouteLogger" type="Magento\Payment\Model\Method\Logger">
        <arguments>
            <argument name="config" xsi:type="object">SmartRouteConfig</argument>
        </arguments>
    </virtualType>

    <!-- Commands infrastructure -->
    <virtualType name="SmartRouteCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
        <arguments>
            <argument name="commands" xsi:type="array">
                <item name="authorize" xsi:type="string">SmartRouteAuthorizeCommand</item>
                <item name="capture" xsi:type="string">SmartRouteCaptureCommand</item>
                <item name="void" xsi:type="string">SmartRouteVoidCommand</item>
            </argument>
        </arguments>
    </virtualType>

    <!-- Authorize command -->
    <virtualType name="SmartRouteAuthorizeCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
        <arguments>
            <argument name="requestBuilder" xsi:type="object">SmartRouteAuthorizationRequest</argument>
            <argument name="handler" xsi:type="object">SmartRouteResponseHandlerComposite</argument>
            <argument name="transferFactory" xsi:type="object">Sts\SmartRoute\Gateway\Http\TransferFactory</argument>
            <argument name="client" xsi:type="object">Sts\SmartRoute\Gateway\Http\Client\ClientMock</argument>
        </arguments>
    </virtualType>

    <!-- Authorization Request -->
    <virtualType name="SmartRouteAuthorizationRequest" type="Magento\Payment\Gateway\Request\BuilderComposite">
        <arguments>
            <argument name="builders" xsi:type="array">
                <item name="transaction" xsi:type="string">Sts\SmartRoute\Gateway\Request\AuthorizationRequest</item>
                <item name="mockData" xsi:type="string">Sts\SmartRoute\Gateway\Request\MockDataRequest</item>
            </argument>
        </arguments>
    </virtualType>
    <type name="Sts\SmartRoute\Gateway\Request\AuthorizationRequest">
        <arguments>
            <argument name="config" xsi:type="object">SmartRouteConfig</argument>
        </arguments>
    </type>

    <!-- Capture command -->
    <virtualType name="SmartRouteCaptureCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
        <arguments>
            <argument name="requestBuilder" xsi:type="object">Sts\SmartRoute\Gateway\Request\CaptureRequest</argument>
            <argument name="handler" xsi:type="object">Sts\SmartRoute\Gateway\Response\TxnIdHandler</argument>
            <argument name="transferFactory" xsi:type="object">Sts\SmartRoute\Gateway\Http\TransferFactory</argument>
            <argument name="validator" xsi:type="object">Sts\SmartRoute\Gateway\Validator\ResponseCodeValidator</argument>
            <argument name="client" xsi:type="object">Sts\SmartRoute\Gateway\Http\Client\ClientMock</argument>
        </arguments>
    </virtualType>

    <!-- Capture Request -->
    <type name="Sts\SmartRoute\Gateway\Request\CaptureRequest">
        <arguments>
            <argument name="config" xsi:type="object">SmartRouteConfig</argument>
        </arguments>
    </type>

    <!-- Void command -->
    <!-- <virtualType name="SmartRouteVoidCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
        <arguments>
            <argument name="requestBuilder" xsi:type="object">Sts\SmartRoute\Gateway\Request\VoidRequest</argument>
            <argument name="handler" xsi:type="object">Sts\SmartRoute\Gateway\Response\TxnIdHandler</argument>
            <argument name="transferFactory" xsi:type="object">Sts\SmartRoute\Gateway\Http\TransferFactory</argument>
            <argument name="validator" xsi:type="object">Sts\SmartRoute\Gateway\Validator\ResponseCodeValidator</argument>
            <argument name="client" xsi:type="object">Sts\SmartRoute\Gateway\Http\Client\ClientMock</argument>
        </arguments>
    </virtualType> -->

    <!-- Void Request -->
    <!--     <type name="Sts\SmartRoute\Gateway\Request\VoidRequest">
        <arguments>
            <argument name="config" xsi:type="object">SmartRouteConfig</argument>
        </arguments>
    </type> -->

    <!-- Response handlers -->
    <virtualType name="SmartRouteResponseHandlerComposite" type="Magento\Payment\Gateway\Response\HandlerChain">
        <arguments>
            <argument name="handlers" xsi:type="array">
                <item name="txnid" xsi:type="string">Sts\SmartRoute\Gateway\Response\TxnIdHandler</item>
                <item name="fraud" xsi:type="string">Sts\SmartRoute\Gateway\Response\FraudHandler</item>
            </argument>
        </arguments>
    </virtualType>

    <!-- Value handlers infrastructure -->
    <virtualType name="SmartRouteValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
        <arguments>
            <argument name="handlers" xsi:type="array">
                <item name="default" xsi:type="string">SmartRouteConfigValueHandler</item>
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="SmartRouteConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
        <arguments>
            <argument name="configInterface" xsi:type="object">SmartRouteConfig</argument>
        </arguments>
    </virtualType>

    <type name="Sts\SmartRoute\Block\Info">
        <arguments>
            <argument name="config" xsi:type="object">SmartRouteConfig</argument>
        </arguments>
    </type>

</config>
