<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system><section id="tbi_settings">
        <group id="autogedal_connection" translate="label" sortOrder="5" showInDefault="1" showInWebsite="0" showInStore="0">
            <label>Autogedal - Connection Environment</label>
            <field id="test_mode" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>Test Mode</label><source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                <comment>Yes: UAT URL and UAT Account. No: Production URL and Production Account. Applies to the entire installation.</comment>
            </field>
            <field id="production_url" translate="label comment" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>Production Platform URL</label><backend_model>Autogedal\TbiBank\Model\Config\Backend\Origin</backend_model><validate>required-entry validate-url</validate><comment>HTTPS origin only, without /api, a path, or query parameters.</comment>
            </field>
            <field id="uat_url" translate="label comment" type="text" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>UAT Platform URL</label><backend_model>Autogedal\TbiBank\Model\Config\Backend\Origin</backend_model><validate>required-entry validate-url</validate><comment>HTTPS origin only. API, calculator and iframe origins follow this URL.</comment>
            </field>
        </group>
        <group id="general_settings">
            <label>Production Account - General Settings</label>
            <field id="encryption_key" type="obscure">
                <backend_model>Autogedal\TbiBank\Model\Config\Backend\EncryptionKey</backend_model>
                <comment>Stored encrypted when a new key is saved. An existing plaintext key remains readable; re-enter it once to encrypt its stored value.</comment>
            </field>
        </group>
        <group id="uat_settings" translate="label" sortOrder="15" showInDefault="1" showInWebsite="0" showInStore="0">
            <label>UAT Account</label>
            <field id="reseller_code" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0"><label>UAT Reseller Code</label></field>
            <field id="reseller_key" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0"><label>UAT Reseller Key</label></field>
            <field id="encryption_key" translate="label comment" type="obscure" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>UAT Encryption Key</label><backend_model>Autogedal\TbiBank\Model\Config\Backend\EncryptionKey</backend_model>
                <comment>Use the public test encryption key from TBI RO FusionPay documentation or the key supplied for your UAT account. Stored encrypted.</comment>
            </field>
            <field id="status" translate="label" type="label" sortOrder="40" showInDefault="1" showInWebsite="0" showInStore="0"><label>UAT Status</label></field>
            <field id="minimum_visible" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="0" showInStore="0"><label>UAT Minimum Amount</label><config_path>tbi_settings/uat_label_settings/minimum_visible</config_path><validate>validate-number validate-zero-or-greater</validate></field>
            <field id="maximum_visible" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="0" showInStore="0"><label>UAT Maximum Amount</label><config_path>tbi_settings/uat_label_settings/maximum_visible</config_path><validate>validate-number validate-zero-or-greater</validate></field>
        </group>
        <group id="approval_settings" translate="label" sortOrder="25" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>TBI Approval and Fulfilment</label>
            <field id="callback_approved_status" translate="label comment" type="text" sortOrder="5" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>TBI Callback Approval Status</label>
                <validate>required-entry</validate>
                <comment>Exact, case-sensitive source status passed by the vendor callback handler. Default: Approved. Do not enter the Romanian translation or a Magento order status. A match records payment and releases the order.</comment>
            </field>
            <field id="require_approval_before_awb" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Require TBI Approval Before AWB</label><source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                <comment>Yes: courier calls are blocked until the TBI approval IPN is received. No: AWB generation is allowed before approval, but the order remains in the TBI waiting status and never becomes Noua until approval.</comment>
            </field>
            <field id="approved_status" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Order Status After TBI Approval</label><source_model>Autogedal\TbiBank\Model\Source\ApprovedStatus</source_model>
                <comment>Default: Noua (new). Approval keeps the project Pending state; operators can then move the order into the normal fulfilment flow. Do not select the waiting status.</comment>
            </field>
            <field id="failure_redirect_path" translate="label comment" type="text" sortOrder="23" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>TBI Rejection Redirect Path</label>
                <validate>required-entry</validate>
                <comment>Relative Magento route path only, without a leading slash, host, query or fragment. Default: tbi/failure.</comment>
            </field>
            <field id="polling_enabled" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0"><label>Check TBI Approval Status Periodically</label><source_model>Magento\Config\Model\Config\Source\Yesno</source_model></field>
            <field id="defer_order_email_until_approval" translate="label" type="select" sortOrder="25" showInDefault="1" showInWebsite="1" showInStore="1"><label>Send New Order Email Only After Approval</label><source_model>Magento\Config\Model\Config\Source\Yesno</source_model></field>
            <field id="polling_schedule" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="0" showInStore="0"><label>Approval Check Frequency</label><source_model>Autogedal\TbiBank\Model\Source\PollingSchedule</source_model></field>
            <field id="remote_approved_statuses" translate="label comment" type="textarea" sortOrder="50" showInDefault="1" showInWebsite="0" showInStore="0"><label>TBI Response Statuses Confirming Approval</label><comment>One exact GetApplicationStatus status per line, confirmed with TBI. Empty means monitoring only: unfamiliar responses never release an order. This is separate from the Magento status selected above.</comment></field>
            <field id="polling_batch_size" translate="label comment" type="text" sortOrder="60" showInDefault="1" showInWebsite="0" showInStore="0"><label>Orders Per Approval Check</label><validate>validate-digits validate-greater-than-zero</validate><comment>Maximum 100. Oldest checked applications are selected first to avoid starving newer orders.</comment></field>
        </group>
    </section></system>
</config>
