private void ensureStoredValuesDontGetErased(
      RegistrationEntity registrationEntityCopyOfApiRegistration,
      RegistrationEntity originalRegistrationEntity) {
    if (registrationEntityCopyOfApiRegistration.getCompletedTimestamp() == null
        && originalRegistrationEntity.getCompletedTimestamp() != null) {
      registrationEntityCopyOfApiRegistration.setCompletedTimestamp(
          originalRegistrationEntity.getCompletedTimestamp());
    }

    if (registrationEntityCopyOfApiRegistration.getTotalDue() == null
        && originalRegistrationEntity.getTotalDue() != null) {
      registrationEntityCopyOfApiRegistration.setTotalDue(originalRegistrationEntity.getTotalDue());
    }
  }
  /**
   * If the registration is being set to completed for the first time, then we need to calculate the
   * total due based on the completed timestamp and early registration data.
   */
  public void setTotalDue(
      Registration apiUpdatedRegistration,
      RegistrationEntity registrationEntityCopyOfApiRegistration,
      RegistrationEntity originalRegistrationEntity,
      CrsApplicationUser loggedInAdmin) {
    if (apiUpdatedRegistration.getCompleted() && !originalRegistrationEntity.getCompleted()) {
      ConferenceCostsEntity conferenceCostsEntity =
          conferenceCostsService.fetchBy(apiUpdatedRegistration.getConferenceId());

      registrationEntityCopyOfApiRegistration.setTotalDue(conferenceCostsEntity.getBaseCost());

      if (conferenceCostsEntity.isEarlyRegistrationDiscount()
          && conferenceCostsEntity.getEarlyRegistrationCutoff() != null
          && registrationEntityCopyOfApiRegistration
              .getCompletedTimestamp()
              .isBefore(conferenceCostsEntity.getEarlyRegistrationCutoff())) {
        registrationEntityCopyOfApiRegistration.setTotalDue(
            conferenceCostsEntity
                .getBaseCost()
                .subtract(conferenceCostsEntity.getEarlyRegistrationAmount()));
      }
    }

    administratorOverrideTotalDue(
        apiUpdatedRegistration,
        registrationEntityCopyOfApiRegistration,
        originalRegistrationEntity,
        loggedInAdmin);

    ensureStoredValuesDontGetErased(
        registrationEntityCopyOfApiRegistration, originalRegistrationEntity);
  }