context: using Newtonsoft.Json;
  using Newtonsoft.Json.Converters;
  using System;
  using System.Collections.Generic;
  using System.Text;
  using USC.GISResearchLab.Common.Core.Addresses.Interfaces;
  using USC.GISResearchLab.Common.Utils.Strings;
  
  namespace USC.GISResearchLab.Common.Addresses.AbstractClasses
  {
  
  
      public abstract class AbstractStreetAddress : AbstractStreetAddressBase, IStreetAddress, ICloneable
      {
  
          #region Properties
  
          [JsonIgnore]
          public List<AddressComponents> SoundexableAttributes { get; set; }
          [JsonIgnore]
          public bool IsParsed { get; set; }
          [JsonIgnore]
          public bool HasPostOfficeBox { get; set; }
          [JsonIgnore]
          public string PostOfficeBoxType { get; set; }
          [JsonIgnore]
          public string PostOfficeBoxNumber { get; set; }
          [JsonIgnore]
          public bool HasPostOfficeBoxNumber
          {
              get { return !String.IsNullOrEmpty(PostOfficeBoxNumber); }
          }
  
          [JsonIgnore]
          public bool HasRuralRoute { get; set; }
          [JsonIgnore]
          public string RuralRouteType { get; set; }
          [JsonIgnore]
          public string RuralRouteNumber { get; set; }
          [JsonIgnore]
          public bool HasRuralRouteNumber
          {
              get { return !String.IsNullOrEmpty(RuralRouteNumber); }
          }
          [JsonIgnore]
          public string RuralRouteBoxType { get; set; }
          [JsonIgnore]
          public string RuralRouteBoxNumber { get; set; }
          [JsonIgnore]
          public bool HasRuralRouteBoxNumber
          {
              get { return !String.IsNullOrEmpty(RuralRouteBoxNumber); }
          }
  
          [JsonIgnore]
          public bool HasRuralRouteBox { get; set; }
          [JsonIgnore]
          public bool HasStarRoute { get; set; }
          [JsonIgnore]
          public string StarRouteType { get; set; }
          [JsonIgnore]
          public string StarRouteNumber { get; set; }
          [JsonIgnore]
          public bool HasStarRouteNumber
          {
              get { return !String.IsNullOrEmpty(StarRouteNumber); }
          }
  
          [JsonIgnore]
          public string StarRouteBoxType { get; set; }
          [JsonIgnore]
          public string StarRouteBoxNumber { get; set; }
          [JsonIgnore]
          public bool HasStarRouteBoxNumber
          {
              get { return !String.IsNullOrEmpty(StarRouteBoxNumber); }
          }
  
          [JsonIgnore]
          public bool HasStarRouteBox { get; set; }
          [JsonIgnore]
          public bool HasHighwayContractRoute { get; set; }
          [JsonIgnore]
          public string HighwayContractRouteType { get; set; }
          [JsonIgnore]
          public string HighwayContractRouteNumber { get; set; }
          [JsonIgnore]
          public bool HasHighwayContractRouteNumber
          {
              get { return !String.IsNullOrEmpty(HighwayContractRouteNumber); }
          }
  
          [JsonIgnore]
          public string HighwayContractRouteBoxType { get; set; }
          [JsonIgnore]
          public string HighwayContractRouteBoxNumber { get; set; }
          [JsonIgnore]
          public bool HasHighwayContractRouteBoxNumber
          {
              get { return !String.IsNullOrEmpty(HighwayContractRouteBoxNumber); }
          }
  
          [JsonIgnore]
          public bool HasHighwayContractRouteBox { get; set; }
  
          [JsonIgnore]
          public string AddressId { get; set; }
  
  
          [JsonIgnore]
          public string NumberWithMultiRanges { get; set; }
  
  
  
          [JsonIgnore]
          public string NonParsedStreetAddress { get; set; }
  
          private StreetAddress _NonParsedOriginalStreetAddress;
          [JsonIgnore]
          public StreetAddress NonParsedOriginalStreetAddress
          {
              get
              {
                  if (_NonParsedOriginalStreetAddress == null)
                  {
                      _NonParsedOriginalStreetAddress = new StreetAddress();
                  }
                  return _NonParsedOriginalStreetAddress;
              }
  
              set
              {
                  _NonParsedOriginalStreetAddress = value;
              }
          }
  
          [JsonConverter(typeof(StringEnumConverter))]
          public new AddressLocationTypes AddressLocationType
          {
              get
              {
                  AddressLocationTypes ret = AddressLocationTypes.Unknown;
  
                  if (HasAddress)
                  {
                      ret = AddressLocationTypes.StreetAddress;
                  }
                  else if (HasPostOfficeBox)
                  {
                      ret = AddressLocationTypes.PostOfficeBox;
                  }
                  else if (HasRuralRoute)
                  {
                      ret = AddressLocationTypes.RuralRoute;
                  }
                  else if (HasStarRoute)
                  {
                      ret = AddressLocationTypes.StarRoute;
                  }
                  else if (HasHighwayContractRoute)
                  {
                      ret = AddressLocationTypes.HighwayContractRoute;
                  }
                  else if (HasZip)
                  {
                      ret = AddressLocationTypes.USPSZIP;
                  }
                  else if (HasCity)
                  {
                      ret = AddressLocationTypes.City;
                  }
                  else if (HasState)
                  {
                      ret = AddressLocationTypes.State;
                  }
                  return ret;
              }
  
          }
  
          #endregion
  
          #region Constructors
          public AbstractStreetAddress()
          { }
  
          public AbstractStreetAddress(string number, string pre, string name, string post, string suffix)
              : this(number, pre, name, post, suffix, null, null, null, null, null, null)
          { }
  
  
          public AbstractStreetAddress(string number, string pre, string name, string post, string suffix, string suite, string suitenumber)
              : this(number, pre, name, post, suffix, suite, suitenumber, null, null, null, null)
          { }
  
          public AbstractStreetAddress(string number, string pre, string name, string suffix, string post, string city, string state, string zip)
              : this(number, pre, name, post, suffix, null, null, city, null, null, null)
          { }
  
          public AbstractStreetAddress(string number, string pre, string name, string suffix, string post, string city, string state, string zip, string country)
              : this(number, pre, name, post, suffix, null, null, city, state, zip, country)
          { }
  
          public AbstractStreetAddress(string number, string pre, string name, string suffix, string post, string suite, string suiteNumber, string city, string state, string zip)
              : this(number, pre, name, post, suffix, suite, suiteNumber, city, state, zip, null)
          { }
  
          public AbstractStreetAddress(string number, string pre, string name, string suffix, string post, string suite, string suiteNumber, string city, string state, string zip, string country)
              : base(pre, name, post, suffix, suite, suiteNumber, city, state, zip, country)
          {
              //NonParsedOriginalValue = "";
              //AddressId = "";
              //Number = "";
              //NumberFractional = "";
  
              //PostOfficeBoxType = "";
              //PostOfficeBoxNumber = "";
              //RuralRouteType = "";
              //RuralRouteNumber = "";
              //RuralRouteBoxType = "";
              //RuralRouteBoxNumber = "";
              SoundexableAttributes = new List<AddressComponents>();
  
              Number = (!String.IsNullOrEmpty(number)) ? number.Trim() : null;
              IsParsed = true;
          }
  
          #endregion
  
          public string GetDeliveryLine()
          {
  
              StringBuilder sb = new StringBuilder();
  
              sb.Append(StringUtils.ValueAndBlankOrNoBlank(Number));
              sb.Append(StringUtils.ValueAndBlankOrNoBlank(NumberFractional));
              sb.Append(StringUtils.ValueAndBlankOrNoBlank(PreDirectional));
              sb.Append(StringUtils.ValueAndBlankOrNoBlank(PreQualifier));
              sb.Append(StringUtils.ValueAndBlankOrNoBlank(PreArticle));
              sb.Append(StringUtils.ValueAndBlankOrNoBlank(PreType));
              sb.Append(StringUtils.ValueAndBlankOrNoBlank(StreetName));
              sb.Append(StringUtils.ValueAndBlankOrNoBlank(PostArticle));
              sb.Append(StringUtils.ValueAndBlankOrNoBlank(Suffix));
              sb.Append(StringUtils.ValueAndBlankOrNoBlank(PostQualifier));
              sb.Append(StringUtils.ValueAndBlankOrNoBlank(PostDirectional));
  
              if (!String.IsNullOrEmpty(SuiteNumber) || !String.IsNullOrEmpty(SuiteType))
              {
                  sb.Append(", ");
                  sb.Append(StringUtils.ValueAndBlankOrNoBlank(SuiteNumber));
                  sb.Append(StringUtils.ValueAndBlankOrNoBlank(SuiteType));
              }
  
              return sb.ToString();
          }
  
          public override string ToString()
          {
              string ret = "";
              //ret += StringUtils.ValueAndBlankOrNoBlank(AddressId);
  
gt:             ret += StringUtils.ValueAndBlankOrNoBlank(Number);