class SecretDAO {

  public Optional<SecretSeriesAndContent> getSecretById(long secretId) {
    return dslContext.<Optional<SecretSeriesAndContent>>transactionResult(configuration -> {
      SecretContentDAO secretContentDAO = secretContentDAOFactory.using(configuration);
      SecretSeriesDAO secretSeriesDAO = secretSeriesDAOFactory.using(configuration);

      Optional<SecretSeries> series = secretSeriesDAO.getSecretSeriesById(secretId);
      if (series.isPresent() && series.get().currentVersion().isPresent()) {
        long secretContentId = series.get().currentVersion().get();
        Optional<SecretContent> contents = secretContentDAO.getSecretContentById(secretContentId);
        if (!contents.isPresent()) {
          throw new IllegalStateException(
              format("failed to fetch secret %d, content %d not found.", secretId,
                  secretContentId));
        }
        return Optional.of(SecretSeriesAndContent.of(series.get(), contents.get()));
      }
      return Optional.empty();
    });
  }

  public  SecretDAO(DSLContext dslContext, SecretContentDAOFactory secretContentDAOFactory,
      SecretSeriesDAOFactory secretSeriesDAOFactory, ContentCryptographer cryptographer);

}