using System.Linq;

namespace Valg.EVA.Skanning.ServicesModel.ElectionConfig.Model
{
    public class PollingDistrict
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public VotingCategory VotingCategory { get; set; }

        public string GetPollingDistrictName()
        {
            if (string.IsNullOrWhiteSpace(Id))
            {
                return Name;
            }
            else
            {
                string pollingDistrict = GetPollingDistrict(Id);
                if (pollingDistrict == "0000")
                {
                    return string.Empty;
                }
                else
                {
                    return string.Format("{0} {1}", pollingDistrict, Name);
                }
            }
        }

        private string GetPollingDistrict(string districtId)
        {
            var parts = districtId.Split('.');
            return parts.LastOrDefault();
        }
    }
}

