﻿namespace Subscription.Domain.Model
{
    public class ReportingArea
    {
        public ReportingArea(string districtCode, string zoneCode, string zoneName, int? regionID, string regionName, ReportingScope scope)
        {
            DistrictCode = districtCode;
            ZoneCode = zoneCode;
            ZoneName = zoneName;
            RegionID = regionID;
            RegionName = regionName;
            Scope = scope;
        }

        public string DistrictCode { get; set; }
        public string ZoneCode { get; set; }
        public string ZoneName { get; private set; }
        public int? RegionID { get; set; }
        public string RegionName { get; private set; }
        public ReportingScope Scope { get; private set; }

        public object EffectiveAreaNameAndScope(out ReportingScope effectiveScope)
        {
            switch (Scope)
            {
                case ReportingScope.NationalAccount:
                case ReportingScope.RegionalAccount:
                case ReportingScope.Company:
                    effectiveScope = ReportingScope.Company;
                    return null;
                case ReportingScope.Region:
                    if (!string.IsNullOrEmpty(RegionName))
                    {
                        effectiveScope = ReportingScope.Region;
                        return RegionName;
                    }
                    effectiveScope = ReportingScope.Company;
                    return null;
                case ReportingScope.Zone:
                    if (!string.IsNullOrEmpty(ZoneName))
                    {
                        effectiveScope = ReportingScope.Zone;
                        return ZoneName;
                    }
                    goto case ReportingScope.Region;
                case ReportingScope.District:
                    if (!string.IsNullOrEmpty(DistrictCode))
                    {
                        effectiveScope = ReportingScope.District;
                        return DistrictCode;
                    }
                    goto case ReportingScope.Zone;
                default:
                    effectiveScope = Scope;
                    return null;

                //case ReportingScope.District:
                //    return DistrictCode;
                //case ReportingScope.Zone:
                //    return ZoneCode;
                //case ReportingScope.Region:
                //    return RegionID.HasValue ? (object)RegionID : (object)ZoneCode;
                //default:
                //    return null;
            }
        }
    }
}
