<?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>
        <tab id="yeboyebo" translate="label" sortOrder="11">
            <label>Yeboyebo</label>
        </tab>
        <section id="yeboyebo_botfilterprotect" translate="label" sortOrder="200" showInDefault="1" showInWebsite="1" showInStore="1">
            <class>separator-top</class>
            <label>Bot Filter Protect</label>
            <tab>yeboyebo</tab>
            <resource>Yeboyebo_BotFilterProtect::config</resource>

            <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>General</label>
                <field id="enabled" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Enable module</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <comment>Master ON/OFF switch. Default OFF. When OFF the plugin returns immediately and behaves as if the module did not exist, without touching any request. Toggle this to instantly disable the feature without a deploy.</comment>
                </field>
                <field id="dry_run" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Dry run mode</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <comment>When ON, the plugin detects matches and writes them to var/log/botfilterprotect.log but does NOT actually redirect. Use this to validate the user-agent and query parameter lists in production before enabling the real redirect.</comment>
                </field>
                <field id="redirect_code" translate="label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Redirect HTTP status code</label>
                    <source_model>Yeboyebo\BotFilterProtect\Model\Config\Source\RedirectCode</source_model>
                    <comment>302 (Found, temporary) is the safe default. Browsers and caches do not hard-cache it, so you can disable the module and user browsers will immediately stop following the redirect. 301 (Moved Permanently) is aggressively cached by browsers and should only be used when you are 100% sure the redirect is permanent.</comment>
                </field>
            </group>

            <group id="triggers" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Triggers (when to redirect)</label>
                <field id="filter_params" translate="label comment" type="textarea" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Query parameters</label>
                    <comment>One per line. The request must contain at least one of these GET query parameters to be a candidate for redirect. Default: customFilters (ScandiPWA faceted navigation parameter that generates the cache-busting cartesian product).</comment>
                </field>
                <field id="bot_user_agents" translate="label comment" type="textarea" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Bot user-agent patterns</label>
                    <comment>One per line. Case-insensitive substring match against the User-Agent header. If the request's User-Agent contains any of these substrings AND one of the query parameters above is present AND the module is enabled, the plugin responds with a redirect to the URL without the query string. Do NOT add Googlebot, Bingbot, Applebot, Prerender, or any search-engine or social-sharing crawler here. Default: AI training and aggressive scraping crawlers that have no business value on a retail site.</comment>
                </field>
            </group>

            <group id="response" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Response</label>
                <field id="cache_control_max_age" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Cache-Control max-age (seconds)</label>
                    <validate>validate-digits validate-not-negative-number</validate>
                    <comment>Seconds to keep the redirect response in Varnish and downstream caches. 86400 = 24 hours. Do not set below 3600 or Varnish will not effectively cache the redirect.</comment>
                </field>
                <field id="debug_header" translate="label comment" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Add X-Bot-Filter-Protect debug header</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <comment>When ON, redirect responses include the header X-Bot-Filter-Protect: 1 so you can verify from curl or logs which requests were intercepted. Turn OFF to keep responses clean.</comment>
                </field>
            </group>
        </section>
    </system>
</config>
