namespace Application.Common;

public static class UserAgentParser
{
    public static string ExtractBrowser(string ua)
    {
        if (ua.Contains("Edg/")) return "Edge";
        if (ua.Contains("Chrome/")) return "Chrome";
        if (ua.Contains("Firefox/")) return "Firefox";
        if (ua.Contains("Safari/") && !ua.Contains("Chrome")) return "Safari";
        if (ua.Contains("MSIE") || ua.Contains("Trident/")) return "IE";
        return "Unknown";
    }

    public static string ExtractOS(string ua)
    {
        if (ua.Contains("Windows NT 10")) return "Windows 10";
        if (ua.Contains("Windows NT 6.3")) return "Windows 8.1";
        if (ua.Contains("Windows NT 6.1")) return "Windows 7";
        if (ua.Contains("Windows")) return "Windows";
        if (ua.Contains("Mac OS X")) return "macOS";
        if (ua.Contains("Android")) return "Android";
        if (ua.Contains("iPhone") || ua.Contains("iPad")) return "iOS";
        if (ua.Contains("Linux")) return "Linux";
        return "Unknown";
    }

    public static string ExtractDevice(string ua)
    {
        if (ua.Contains("Mobile") || ua.Contains("Android") && !ua.Contains("Tablet")) return "Mobile";
        if (ua.Contains("Tablet") || ua.Contains("iPad")) return "Tablet";
        return "Desktop";
    }
}