<?php

declare(strict_types=1);

/**
 * Default detection-engine configuration.
 *
 * These values SEED the database (module_configs + thresholds) on first
 * migrate. After install, the admin panel is the source of truth and edits are
 * read from the DB — this file is only the factory default / fallback.
 *
 * Each module entry: key => [enabled, weight, class]. The engine normalizes
 * every module's raw output to 0..1, multiplies by weight, and divides by the
 * sum of enabled weights to yield a 0..100 human score.
 */

use BotGuard\Services\Detection\Modules;

return [
    // Score bands (inclusive lower bound). Editable in Admin > Thresholds.
    'thresholds' => [
        'human'      => (int) env('THRESHOLD_HUMAN', 80),      // >= human  => Human
        'suspicious' => (int) env('THRESHOLD_SUSPICIOUS', 60), // >= susp   => Suspicious, else Bot
    ],

    // What to do for each classification. Actions: 'redirect_primary',
    // 'redirect_alternate', 'block', 'allow'. Configurable per user later.
    'actions' => [
        'human'      => 'redirect_primary',
        'suspicious' => 'redirect_alternate',
        'bot'        => 'block',
    ],

    // Modules registry. Order is display order in the admin panel.
    'modules' => [
        'user_agent' => [
            'enabled' => true,
            'weight'  => 15,
            'label'   => 'User-Agent Analysis',
            'class'   => Modules\UserAgentModule::class,
            'group'   => 'server',
        ],
        'headers' => [
            'enabled' => true,
            'weight'  => 15,
            'label'   => 'HTTP Header Fingerprinting',
            'class'   => Modules\HttpHeaderModule::class,
            'group'   => 'server',
        ],
        'referrer' => [
            'enabled' => true,
            'weight'  => 5,
            'label'   => 'Referrer Analysis',
            'class'   => Modules\ReferrerModule::class,
            'group'   => 'server',
        ],
        'rate_limit' => [
            'enabled' => true,
            'weight'  => 10,
            'label'   => 'Rate Limiting',
            'class'   => Modules\RateLimitModule::class,
            'group'   => 'server',
        ],
        'session' => [
            'enabled' => true,
            'weight'  => 10,
            'label'   => 'Session Analysis',
            'class'   => Modules\SessionModule::class,
            'group'   => 'server',
        ],
        'fingerprint' => [
            'enabled' => true,
            'weight'  => 15,
            'label'   => 'Browser Fingerprinting',
            'class'   => Modules\BrowserFingerprintModule::class,
            'group'   => 'client',
        ],
        'javascript' => [
            'enabled' => true,
            'weight'  => 10,
            'label'   => 'JavaScript Execution',
            'class'   => Modules\JavaScriptModule::class,
            'group'   => 'client',
        ],
        'cookies' => [
            'enabled' => true,
            'weight'  => 5,
            'label'   => 'Cookie Behavior',
            'class'   => Modules\CookieModule::class,
            'group'   => 'client',
        ],
        'timing' => [
            'enabled' => true,
            'weight'  => 10,
            'label'   => 'Request Timing',
            'class'   => Modules\TimingModule::class,
            'group'   => 'client',
        ],
        'honeypot' => [
            'enabled' => true,
            'weight'  => 15,
            'label'   => 'Honeypot Fields',
            'class'   => Modules\HoneypotModule::class,
            'group'   => 'client',
        ],
        // Behavioral modules. Enabled by default; each stays neutral when the
        // relevant interaction did not occur (e.g. no typing, touch device), so
        // they reward genuine human behaviour without punishing its absence.
        'mouse' => [
            'enabled' => true,
            'weight'  => 20,
            'label'   => 'Mouse Movement Analysis',
            'class'   => Modules\MouseModule::class,
            'group'   => 'client',
        ],
        'keyboard' => [
            'enabled' => true,
            'weight'  => 10,
            'label'   => 'Keyboard Behavior',
            'class'   => Modules\KeyboardModule::class,
            'group'   => 'client',
        ],
        'scroll' => [
            'enabled' => true,
            'weight'  => 10,
            'label'   => 'Scroll Behavior',
            'class'   => Modules\ScrollModule::class,
            'group'   => 'client',
        ],
        'link_interaction' => [
            'enabled' => true,
            'weight'  => 5,
            'label'   => 'Link Interaction',
            'class'   => Modules\LinkInteractionModule::class,
            'group'   => 'client',
        ],
        'captcha' => [
            'enabled' => true,
            'weight'  => 20,
            'label'   => 'CAPTCHA / Puzzle Verification',
            'class'   => Modules\CaptchaModule::class,
            'group'   => 'client',
        ],
    ],
];
