using Nalu.Web.PostProcessors;

namespace Nalu.Web.PostProcessors;

public class RemoveTitles : IPostProcessor
{
    public string Name => "remove_titles";

    private static readonly HashSet<string> Titles = new(StringComparer.OrdinalIgnoreCase)
    {
        "Dr.", "Dr", "Dra.", "Dra", "Sr.", "Sr", "Sra.", "Sra",
        "Prof.", "Prof", "Profa.", "Profa", "Eng.", "Eng",
        "Doutor", "Doutora", "Senhor", "Senhora", "Me.", "Me", "Msc"
    };

    public ProcessorResult Process(string? value)
    {
        if (string.IsNullOrWhiteSpace(value)) return ProcessorResult.Ok(value);

        var words = value
            .Split(' ', StringSplitOptions.RemoveEmptyEntries)
            .Where(w => !Titles.Contains(w))
            .ToArray();

        var result = string.Join(' ', words);
        return ProcessorResult.Ok(string.IsNullOrWhiteSpace(result) ? value : result);
    }
}
