namespace RealCV.Application.Data;

/// <summary>
/// Known diploma mills and fake educational institutions.
/// Sources: HEDD, Oregon ODA, UNESCO warnings, Michigan AG list
/// </summary>
public static class DiplomaMills
{
    /// <summary>
    /// Known diploma mills and unaccredited institutions that sell fake degrees.
    /// This list includes institutions identified by various regulatory bodies.
    /// </summary>
    public static readonly HashSet<string> KnownDiplomaMills = new(StringComparer.OrdinalIgnoreCase)
    {
        // Well-known diploma mills
        "Almeda University",
        "Ashwood University",
        "Belford University",
        "Bircham University",
        "Breyer State University",
        "Brighton University (not Brighton UK)",
        "Buxton University",
        "Cambridge State University",
        "Chadwick University",
        "Clayton University",
        "Columbus University",
        "Corllins University",
        "Dartington University",
        "Dickinson State University Online",
        "Fairfax University",
        "Glendale University",
        "Greenleaf University",
        "Hamilton University",
        "Harrington University",
        "Hill University",
        "Hollywood University",
        "International University (generic)",
        "Irish International University",
        "James Monroe University",
        "Jamestown University",
        "Kennedy-Western University",
        "Kensington University",
        "Knightsbridge University",
        "LaSalle University (Louisiana)",
        "Lexington University",
        "Lincoln University (if not Pennsylvania)",
        "Madison University",
        "Metropolitan University (generic)",
        "Middletown University",
        "Monticello University",
        "Northern University",
        "Northfield University",
        "Pacific Southern University",
        "Pacific Western University",
        "Paramount University",
        "Parkwood University",
        "Preston University",
        "Redding University",
        "Richmond University (not American Intl)",
        "Robertstown University",
        "Rochdale University",
        "Rochville University",
        "Saint Regis University",
        "St Regis University",
        "Shaftesbury University",
        "Shelbourne University",
        "Stanton University",
        "Stratford University (if unaccredited)",
        "Suffield University",
        "Summit University (diploma mill)",
        "Sussex College of Technology",
        "Trinity College and University",
        "Trinity Southern University",
        "University Degree Program",
        "University of Atlanta",
        "University of Berkley",
        "University of Devonshire",
        "University of Dunham",
        "University of England",
        "University of Northern Washington",
        "University of Palmers Green",
        "University of San Moritz",
        "University of Sussex (fake - not real Sussex)",
        "University of Wexford",
        "Vocational University",
        "Warnborough University",
        "Washington International University",
        "Weston Reserve University",
        "Westbourne University",
        "Western States University",
        "Woodfield University",
        "Yorker International University",

        // Pakistani diploma mills commonly seen in UK
        "Axact University",
        "Brooklyn Park University",
        "Columbiana University",
        "Hillford University",
        "Nixon University",
        "Oxbridge University",
        "University of Newford",

        // Online diploma mills
        "American World University",
        "Ashford University (pre-2005)",
        "Concordia College and University",
        "Columbus State University (fake)",
        "Frederick Taylor University",
        "International Theological University",
        "Nations University",
        "Paramount California University",
        "University of Ancient Studies",
        "University of Asia",
        "Virtual University (unaccredited)",
    };

    /// <summary>
    /// Suspicious patterns in institution names that often indicate diploma mills.
    /// </summary>
    public static readonly string[] SuspiciousPatterns =
    [
        "online university",
        "virtual university",
        "life experience",
        "no classes required",
        "degree in days",
        "accredited by",      // followed by fake accreditor
        "internationally recognised",
        "worldwide university",
        "global university",
        "premier university",
        "elite university",
        "executive university",
        "professional university",
        "distance learning university", // be careful - some are legit
    ];

    /// <summary>
    /// Fake accreditation bodies used by diploma mills.
    /// </summary>
    public static readonly HashSet<string> FakeAccreditors = new(StringComparer.OrdinalIgnoreCase)
    {
        "World Association of Universities and Colleges",
        "WAUC",
        "International Accreditation Agency",
        "Universal Accreditation Council",
        "Board of Online Universities Accreditation",
        "International Council for Open and Distance Education",
        "World Online Education Accrediting Commission",
        "Central States Consortium of Colleges and Schools",
        "American Council of Private Colleges and Universities",
        "Association of Distance Learning Programs",
        "International Distance Education Certification Agency",
    };

    /// <summary>
    /// Check if an institution is a known diploma mill.
    /// </summary>
    public static bool IsDiplomaMill(string institutionName)
    {
        if (string.IsNullOrWhiteSpace(institutionName))
            return false;

        var normalised = institutionName.Trim();

        // Direct match
        if (KnownDiplomaMills.Contains(normalised))
            return true;

        // Check if name contains known diploma mill
        foreach (var mill in KnownDiplomaMills)
        {
            if (normalised.Contains(mill, StringComparison.OrdinalIgnoreCase))
                return true;
        }

        return false;
    }

    /// <summary>
    /// Check if institution name has suspicious patterns common in diploma mills.
    /// Returns true if suspicious (but not confirmed fake).
    /// </summary>
    public static bool HasSuspiciousPattern(string institutionName)
    {
        if (string.IsNullOrWhiteSpace(institutionName))
            return false;

        var lower = institutionName.ToLowerInvariant();

        foreach (var pattern in SuspiciousPatterns)
        {
            if (lower.Contains(pattern))
                return true;
        }

        return false;
    }

    /// <summary>
    /// Check if an accreditor is known to be fake.
    /// </summary>
    public static bool IsFakeAccreditor(string accreditorName)
    {
        if (string.IsNullOrWhiteSpace(accreditorName))
            return false;

        return FakeAccreditors.Contains(accreditorName.Trim());
    }
}
