namespace Ikar.Shared;

public static class PhoneNumberNormalizer
{
    public static string? Normalize(string? phoneNumber)
    {
        if (string.IsNullOrWhiteSpace(phoneNumber))
        {
            return null;
        }

        var digits = new string(phoneNumber.Where(char.IsDigit).ToArray());
        if (digits.Length < 10)
        {
            return null;
        }

        return digits.Length == 10
            ? digits
            : digits[^10..];
    }
}
