private void ValidatePaymentLevel()
        {
            RuleFor(x => x.Id)
            .Must(x => x != Guid.Empty)
            .WithMessage(DeactivatePaymentLevelErrors.Requred)
            .Must(x =>
            {
                _oldPaymentLevel = _paymentRepository.PaymentLevels.SingleOrDefault(y => y.Id == x);

                return(_oldPaymentLevel != null);
            })
            .WithMessage(DeactivatePaymentLevelErrors.NotFound)
            .Must(x => _oldPaymentLevel.Status == PaymentLevelStatus.Active)
            .WithMessage(DeactivatePaymentLevelErrors.NotActive)
            .Must((data, x) =>
            {
                var deactivatePaymentLevelStatus = _paymentLevelQueries.GetDeactivatePaymentLevelStatus(x);

                _newPaymentLevelRequired =
                    deactivatePaymentLevelStatus == DeactivatePaymentLevelStatus.CanDeactivateIsAssigned ||
                    deactivatePaymentLevelStatus == DeactivatePaymentLevelStatus.CanDeactivateIsDefault;

                return(!_newPaymentLevelRequired ||
                       (data.NewPaymentLevelId.HasValue && data.NewPaymentLevelId.Value != Guid.Empty));
            })
            .WithMessage(DeactivatePaymentLevelErrors.NewPaymentLevelRequired);
        }
        public string Deactivate(Guid id)
        {
            var status     = _paymentLevelQueries.GetDeactivatePaymentLevelStatus(id);
            var statusName = Enum.GetName(typeof(DeactivatePaymentLevelStatus), status);

            var newLevelsRequired = status == DeactivatePaymentLevelStatus.CanDeactivateIsAssigned ||
                                    status == DeactivatePaymentLevelStatus.CanDeactivateIsDefault;

            var paymentLevels = newLevelsRequired
                ? _paymentLevelQueries.GetReplacementPaymentLevels(id).Select(x => new { x.Id, x.Name })
                : null;

            return(SerializeJson(new
            {
                status = statusName,
                paymentLevels
            }));
        }