class PasswordService {

    @VisibleForTesting
    Optional<Instant> calculateExpirationTime(String actorCrn, String accountId) {
        LOGGER.debug("calculating expiration time for password in account {}", accountId);
        UserManagementProto.Account account = umsClient.getAccountDetails(INTERNAL_ACTOR_CRN, accountId, MDCUtils.getRequestId());
        if (account.hasPasswordPolicy()) {
            long maxLifetime = account.getPasswordPolicy().getWorkloadPasswordMaxLifetime();
            if (maxLifetime != 0L) {
                LOGGER.debug("Calculating password expiration by adding lifetime '{}' to current time", maxLifetime);
                return Optional.of(clock.getCurrentInstant().plusMillis(maxLifetime));
            } else {
                LOGGER.debug("Password policy lifetime is {}. Using max expiration time", maxLifetime);
                return Optional.empty();
            }
        } else {
            LOGGER.debug("Account {} does not have a password policy. Using max expiration time for password", accountId);
            return Optional.empty();
        }
    }

}