<?php

declare(strict_types=1);

namespace BotGuard\Tests\Unit;

use BotGuard\Services\Detection\SignalBag;

/**
 * Deterministic signal fixtures representing a clearly-human and a clearly-bot
 * session. Used across engine and module tests so expectations are stable.
 */
final class SignalFixtures
{
    /**
     * A realistic desktop Chrome visitor that solved the challenge.
     */
    public static function human(): SignalBag
    {
        return SignalBag::fromArrays(
            [
                'ip'         => '203.0.113.10',
                'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
                'referer'    => 'https://www.google.com/search?q=example',
                'headers'    => [
                    'accept'          => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,*/*;q=0.8',
                    'accept-language' => 'en-US,en;q=0.9',
                    'accept-encoding' => 'gzip, deflate, br',
                    'sec-ch-ua'       => '"Chromium";v="126", "Not.A/Brand";v="24"',
                    'sec-fetch-site'  => 'none',
                    'sec-fetch-mode'  => 'navigate',
                    'connection'      => 'keep-alive',
                ],
            ],
            [
                'fingerprint' => [
                    'screen_width' => 1920, 'screen_height' => 1080, 'timezone' => 'America/New_York',
                    'languages' => ['en-US', 'en'], 'canvas_hash' => 'a1b2c3d4e5', 'audio_hash' => 'f6g7h8',
                    'webgl_vendor' => 'Google Inc. (NVIDIA)', 'webgl_renderer' => 'ANGLE (NVIDIA GeForce RTX 3060)',
                    'hardware_concurrency' => 8, 'device_memory' => 8, 'color_depth' => 24, 'touch_support' => false,
                    'plugins' => ['PDF Viewer', 'Chrome PDF Viewer'], 'fonts' => ['Arial', 'Calibri', 'Times New Roman', 'Georgia'],
                    'hash' => 'deadbeefcafe',
                ],
                'javascript' => ['enabled' => true, 'es6' => true, 'async' => true, 'promise' => true, 'event_loop' => true, 'webdriver' => false],
                'cookies'    => ['enabled' => true, 'persisted' => true, 'local_storage' => true, 'session_storage' => true],
                'timing'     => ['time_on_page_ms' => 7400, 'time_to_interact_ms' => 1200, 'time_to_submit_ms' => 5200],
                'honeypot'   => ['contact_email' => '', 'website' => '', 'render_delay_ms' => 6100],
                'mouse'      => ['move_count' => 180, 'speed_stddev' => 0.42, 'straightness' => 0.71, 'avg_curvature' => 0.15, 'click_count' => 3, 'click_interval_stddev' => 220.0],
                'keyboard'   => ['keydown_count' => 0],
                'scroll'     => ['event_count' => 12, 'total_distance' => 2300, 'speed_stddev' => 0.3, 'direction_changes' => 3, 'dwell_ms' => 900],
                'links'      => ['hover_count' => 4, 'avg_hover_ms' => 320.0, 'instant_clicks' => 0, 'double_clicks' => 0, 'touch_events' => 0],
                'captcha'    => ['provider' => 'puzzle', 'verified' => true, 'solve_time_ms' => 2600, 'retries' => 0],
                'rate'       => ['per_second' => 1, 'per_minute' => 3, 'per_hour' => 12],
                'session'    => ['duration_ms' => 7400, 'request_count' => 2, 'repeat_visitor' => false, 'integrity_ok' => true, 'navigation_count' => 1],
            ],
        );
    }

    /**
     * A headless automation client with no browser telemetry.
     */
    public static function bot(): SignalBag
    {
        return SignalBag::fromArrays(
            [
                'ip'         => '198.51.100.7',
                'user_agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/126.0.0.0 Safari/537.36',
                'referer'    => '',
                'headers'    => [
                    'accept'     => '*/*',
                    'connection' => 'close',
                ],
            ],
            [
                'fingerprint' => [
                    'screen_width' => 800, 'screen_height' => 600, 'timezone' => '',
                    'languages' => [], 'canvas_hash' => '', 'audio_hash' => '',
                    'webgl_vendor' => 'Google Inc. (Google)', 'webgl_renderer' => 'ANGLE (Google, SwiftShader)',
                    'hardware_concurrency' => 1, 'device_memory' => 0, 'color_depth' => 24, 'touch_support' => false,
                    'plugins' => [], 'fonts' => [],
                ],
                'javascript' => ['enabled' => true, 'es6' => true, 'async' => true, 'promise' => true, 'event_loop' => true, 'webdriver' => true],
                'cookies'    => ['enabled' => false, 'persisted' => false, 'local_storage' => false, 'session_storage' => false],
                'timing'     => ['time_on_page_ms' => 120, 'time_to_interact_ms' => 20, 'time_to_submit_ms' => 90],
                'honeypot'   => ['contact_email' => 'spam@bot.test', 'website' => 'http://bot.test', 'render_delay_ms' => 60],
                'mouse'      => [],
                'keyboard'   => ['keydown_count' => 0],
                'scroll'     => [],
                'links'      => ['hover_count' => 0, 'avg_hover_ms' => 0.0, 'instant_clicks' => 5, 'double_clicks' => 4, 'touch_events' => 0],
                'captcha'    => ['provider' => 'puzzle', 'verified' => false, 'solve_time_ms' => 40, 'retries' => 6],
                'rate'       => ['per_second' => 20, 'per_minute' => 300, 'per_hour' => 5000],
                'session'    => ['duration_ms' => 120, 'request_count' => 40, 'repeat_visitor' => false, 'integrity_ok' => false, 'navigation_count' => 0],
            ],
        );
    }
}
