<?php

declare(strict_types=1);

namespace App\Framework\UserAgent\Enums;

/**
 * Enum representing different browser types
 */
enum BrowserType: string
{
    case CHROME = 'chrome';
    case FIREFOX = 'firefox';
    case SAFARI = 'safari';
    case EDGE = 'edge';
    case OPERA = 'opera';
    case INTERNET_EXPLORER = 'internet_explorer';
    case SAMSUNG_BROWSER = 'samsung_browser';
    case BRAVE = 'brave';
    case VIVALDI = 'vivaldi';
    case UNKNOWN = 'unknown';

    /**
     * Get human-readable name
     */
    public function getDisplayName(): string
    {
        return match ($this) {
            self::CHROME => 'Chrome',
            self::FIREFOX => 'Firefox',
            self::SAFARI => 'Safari',
            self::EDGE => 'Edge',
            self::OPERA => 'Opera',
            self::INTERNET_EXPLORER => 'Internet Explorer',
            self::SAMSUNG_BROWSER => 'Samsung Browser',
            self::BRAVE => 'Brave',
            self::VIVALDI => 'Vivaldi',
            self::UNKNOWN => 'Unknown',
        };
    }

    /**
     * Get browser engine family
     */
    public function getEngine(): EngineType
    {
        return match ($this) {
            self::CHROME, self::EDGE, self::OPERA, self::SAMSUNG_BROWSER, self::BRAVE, self::VIVALDI => EngineType::BLINK,
            self::SAFARI => EngineType::WEBKIT,
            self::FIREFOX => EngineType::GECKO,
            self::INTERNET_EXPLORER => EngineType::TRIDENT,
            self::UNKNOWN => EngineType::UNKNOWN,
        };
    }

    /**
     * Check if browser is considered modern
     */
    public function isModern(): bool
    {
        return match ($this) {
            self::CHROME, self::FIREFOX, self::SAFARI, self::EDGE, self::OPERA,
            self::SAMSUNG_BROWSER, self::BRAVE, self::VIVALDI => true,
            self::INTERNET_EXPLORER, self::UNKNOWN => false,
        };
    }

    /**
     * Get minimum version considered modern for this browser
     */
    public function getModernVersionThreshold(): string
    {
        return match ($this) {
            self::CHROME => '60.0',
            self::FIREFOX => '55.0',
            self::SAFARI => '11.0',
            self::EDGE => '79.0',
            self::OPERA => '47.0',
            self::SAMSUNG_BROWSER => '7.0',
            self::BRAVE => '1.0',
            self::VIVALDI => '2.0',
            self::INTERNET_EXPLORER, self::UNKNOWN => '999.0', // Never modern
        };
    }
}
