namespace Meezi.Core.Utilities;

/// <summary>Lightweight normalization for Persian discover text search.</summary>
public static class PersianSearchNormalizer
{
    public static string Normalize(string? input)
    {
        if (string.IsNullOrWhiteSpace(input))
            return string.Empty;

        var s = input.Trim().ToLowerInvariant();
        s = s.Replace('ي', 'ی')
            .Replace('ك', 'ک')
            .Replace('\u200c', ' ')
            .Replace('\u0640', ' ')
            .Replace("آ", "ا")
            .Replace("أ", "ا")
            .Replace("إ", "ا");

        while (s.Contains("  ", StringComparison.Ordinal))
            s = s.Replace("  ", " ", StringComparison.Ordinal);

        return s;
    }
}
