using Hotline.Share.Enums.CallCenter;

namespace Hotline.Tools
{
    /// <summary>
    /// 电话号码获取运营商工具类
    /// </summary>
    public static class PhoneIspTool
    {
        public static EPhoneISP GetPhoneIsp(string phoneNum)
        {
            if (!string.IsNullOrEmpty(phoneNum))
            {
                //移动号码段
                string cm = "134,135,136,137,138,139,150,151,152,157,158,159,182,183,187,188,147,";
                //联通号码段
                string cu = "130,131,132,155,156,186,145,";
                //电信 号码段
                string ct = "133,153,189,";
                if (phoneNum.Substring(0,1)=="0")
                {
                    phoneNum = phoneNum.Remove(0,1);
                }
                string noSegment = phoneNum.Substring(0, 3) + ",";

                if (cm.IndexOf(noSegment, StringComparison.Ordinal)>=0)
                {
                    return EPhoneISP.CM;
                }
                else if (cu.IndexOf(noSegment, StringComparison.Ordinal) >= 0)
                {
                    return EPhoneISP.CU;
                }else if (ct.IndexOf(noSegment, StringComparison.Ordinal) >= 0)
                {
                    return EPhoneISP.CT;
                }
                else
                {
                    return EPhoneISP.NULL;
                }

            }

            return EPhoneISP.NULL;
        }
    }
}
