namespace Meezi.Core.Utilities;

public static class PhoneNormalizer
{
    public static string Normalize(string phone)
    {
        var digits = new string(phone.Where(char.IsDigit).ToArray());

        if (digits.StartsWith("98") && digits.Length == 12)
            digits = "0" + digits[2..];

        if (digits.Length == 10 && digits.StartsWith('9'))
            digits = "0" + digits;

        return digits;
    }

    public static bool IsValidIranMobile(string normalized) =>
        normalized.Length == 11 && normalized.StartsWith("09");
}
