/**
   * 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);
  }