<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <!-- Custom logger for SimplyIN module (virtualType pattern - standard Magento approach) -->
    <virtualType name="Simplyin\Payment\Logger\VirtualHandler" type="Magento\Framework\Logger\Handler\Base">
        <arguments>
            <argument name="fileName" xsi:type="string">/var/log/simplyin_payment.log</argument>
        </arguments>
    </virtualType>
    <virtualType name="Simplyin\Payment\Logger\VirtualLogger" type="Magento\Framework\Logger\Monolog">
        <arguments>
            <argument name="name" xsi:type="string">simplyin_payment</argument>
            <argument name="handlers" xsi:type="array">
                <item name="system" xsi:type="object">Simplyin\Payment\Logger\VirtualHandler</item>
            </argument>
        </arguments>
    </virtualType>

    <!-- Inject the custom logger into all SimplyIN controllers and services -->
    <!-- ApiClient is now a facade and no longer uses the logger directly; logging moved to the transport/sub-clients below -->
    <type name="Simplyin\Payment\Service\Api\ApiTransport">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Service\OrderSyncService">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Model\OrderSyncRecorder">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Service\OrderPayloadBuilder">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Service\OrderDateFormatter">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Service\OrderDataEnricher">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Service\CreateOrderDataEnricher">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Service\ProductAttributesResolver">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Service\VisibleProductUrlResolver">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Service\CheckoutSessionRestorer">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Service\PlaceOrderFinalizer">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\CheckEmail">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\AddAddress">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\AddParcelLocker">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\CheckPushStatus">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\CreateAccount">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\CreateOrder">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\DeleteAddress">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\DeleteParcelLocker">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\GetParcelLockers">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\GetPaymentMethods">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\GetUserData">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\PlaceMagentoOrder">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\ProcessPayment">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\ResendOtp">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\SearchAddress">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\SetPickupPoint">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\UpdateAddress">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\UpdateOrderPayment">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\UpdateShippingMethod">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\VerifyOtp">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\VerifyPayment">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Api\CheckPaymentStatus">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Payment\Return3DS">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Controller\Webhook\OrderUpdate">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Observer\CreateSimplyinAccountOnOrder">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Model\Queue\OrderStatusUpdateConsumer">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Model\Queue\OrderSyncPostPlacementConsumer">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>

    <!-- RSA request signing + registration (clean RSA-only auth) -->
    <type name="Simplyin\Payment\Model\Auth\RsaSigner">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Model\Auth\RsaRegistrar">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Http\SigningCurlClient">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Model\Auth\RsaRevoker">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Observer\ConfigChangeSync">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>
    <type name="Simplyin\Payment\Model\Auth\WebhookAuthenticator">
        <arguments>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>

    <!--
        CSRF validation is handled per-controller via CsrfAwareActionInterface.
        API controllers use CsrfAwareApiTrait (validates X-Requested-With header).
        Webhook controller validates via HMAC/IP whitelist.
        Return3DS allows all (external bank redirect).
    -->

    <!-- Fix malformed payment method options in admin grid -->
    <type name="Magento\Backend\Block\Widget\Grid\Column\Filter\Select">
        <plugin name="simplyin_fix_payment_options" type="Simplyin\Payment\Plugin\FixPaymentMethodOptions" sortOrder="10" />
    </type>

    <!-- Pickup Point Processor Interface preference -->
    <preference for="Simplyin\Payment\Api\PickupPointProcessorInterface" type="Simplyin\Payment\Model\PickupPointProcessor" />

    <!-- Inject integrators into PickupPointProcessor via DI array.
         Each integrator internally checks if its target module is enabled via ModuleManager.
         If a third-party module (InPost, DPD, Orlen) is not installed, the integrator
         simply returns false from isAvailable() — no class-not-found errors. -->
    <type name="Simplyin\Payment\Model\PickupPointProcessor">
        <arguments>
            <argument name="integrators" xsi:type="array">
                <item name="inpost" xsi:type="object">Simplyin\Payment\Model\Integrator\InpostIntegrator</item>
                <item name="orlen" xsi:type="object">Simplyin\Payment\Model\Integrator\OrlenIntegrator</item>
                <item name="dpd" xsi:type="object">Simplyin\Payment\Model\Integrator\DpdIntegrator</item>
            </argument>
            <argument name="logger" xsi:type="object">Simplyin\Payment\Logger\VirtualLogger</argument>
        </arguments>
    </type>

    <!-- Save SimplyIN account creation data for logged-in customers -->
    <type name="Magento\Checkout\Model\PaymentInformationManagement">
        <plugin name="simplyin_save_account_data" type="Simplyin\Payment\Plugin\SaveSimplyinAccountData" sortOrder="10" />
    </type>

    <!-- Save SimplyIN account creation data for guest checkout -->
    <type name="Magento\Checkout\Model\GuestPaymentInformationManagement">
        <plugin name="simplyin_guest_save_account_data" type="Simplyin\Payment\Plugin\GuestSaveSimplyinAccountData" sortOrder="10" />
    </type>
</config>
