private static string ArrayToString(PhoneNumber[] array)
        {
            StringBuilder stringBuilder = new StringBuilder();

            foreach(var number in array)
            {
                stringBuilder.Append(number.GetValue + " ");
            }

            return stringBuilder.ToString();
        }
        public FavoriteNumbersTariffPlan(PhoneNumber[] favoriteNumbers)
        {
            _FavoriteNumbers = new PhoneNumber[2];

            int index = 0;
            if (favoriteNumbers.Count() > _FavoriteNumbers.Count())
            {
                index = favoriteNumbers.Count() - 2;
            }

            favoriteNumbers.CopyTo(_FavoriteNumbers, index);
        }
        public bool ChangeTariffPlan(PhoneNumber phoneNumber, ITariffPlan tariffPlan)
        {
            if (_TariffPlans.Select(x => tariffPlan.GetType()).Contains(tariffPlan.GetType()))
            {
                var dateTime = LocalDateTime.Now;

                _Logger.WriteToLog("-> User with number " + phoneNumber.GetValue + " want change tariff " + dateTime.ToShortDateString());

                var currentContract = _CurrentContracts.SingleOrDefault(x => x.Number == phoneNumber);

                if (currentContract != null && currentContract.Date.Month != dateTime.Month)
                {
                    var newContract = new Contract(phoneNumber, tariffPlan, dateTime);
                    _CurrentContracts.Remove(currentContract);
                    _OldContracts.Add(currentContract);

                    _CurrentContracts.Add(newContract);
                    _Logger.WriteToLog("Tariff changed on " + tariffPlan.Name);
                    return true;
                }
            }
            _Logger.WriteToLog("Tariff was not changed");
            return false;
        }
 public Request(PhoneNumber sourceNumber, PhoneNumber targetNumber)
 {
     this.SourceNumber = sourceNumber;
     this.TargetNumber = targetNumber;
 }
        public ITerminal ConcludeContract(ITariffPlan tariffPlan)
        {
            if (_TariffPlans.Select(x => tariffPlan.GetType()).Contains(tariffPlan.GetType()))
            {
                var phoneNumber = new PhoneNumber(_NumberCode + _Number.ToString());
                _Number++;

                var dateTime = LocalDateTime.Now;
                var newContract = new Contract(phoneNumber, tariffPlan.GetNewInstance(), dateTime);
                _CurrentContracts.Add(newContract);
                _LastPayment.Add(phoneNumber, dateTime);

                var newTerminal = new Terminal(phoneNumber, _Logger);

                _Logger.WriteToLog("-> Billing system conclude contract");
                _Logger.WriteToLog(ObjectToLogString.ToLogString(newContract));

                OnContract(this, newTerminal);
                return newTerminal;
            }
            return null;
        }
        public void Pay(PhoneNumber phoneNumber)
        {
            var calls = _NotPayCalls.Where(x => x.Source == phoneNumber).ToList();
            _PaiedCalls = _PaiedCalls.Concat(calls).ToList();

            var time = LocalDateTime.Now;
            _LastPayment[phoneNumber] =
                new DateTime(time.Year, time.Month , _CurrentContracts.SingleOrDefault(x => x.Number == phoneNumber).Date.Day);

            _Logger.WriteToLog("User with number " + phoneNumber.GetValue + " pay for calls");

            _Debtors.Remove(phoneNumber);
            _NotPayCalls = _NotPayCalls.Where(x => x.Source != phoneNumber).ToList();
        }
 public bool IsDebtor(PhoneNumber phoneNumber)
 {
     return !_Debtors.Contains(phoneNumber);
 }
 public double GetDebtOnCurrentMoment(PhoneNumber phoneNumber)
 {
     return _NotPayCalls
         .Where(x => x.Source == phoneNumber)
         .Sum(x => x.Price);
 }
 public Terminal(PhoneNumber number, ILogger logger)
 {
     this._PhoneNumber = number;
     this._Logger = logger;
 }
        public void SendRequest(PhoneNumber targetNumber)
        {
            if (OnRequest != null)
            {
                if (_ActiveCall != null)
                {
                    this.TerminateConnection();
                }
                _ActiveCall = new Request(_PhoneNumber, targetNumber);

                _Logger.WriteToLog("-> Send request");
                _Logger.WriteToLog(ObjectToLogString.ToLogString(_ActiveCall));

                OnRequest(this, _ActiveCall);
            }
        }
 public Contract(PhoneNumber number, ITariffPlan tariffPlan, DateTime date)
 {
     this.Number = number;
     this.TariffPlan = tariffPlan;
     this.Date = date;
 }
 public CallInfo(PhoneNumber source, PhoneNumber target)
 {
     this.Source = source;
     this.Target = target;
 }
 public FavoriteNumbersTariffPlan()
 {
     _FavoriteNumbers = new PhoneNumber[2];
 }