package ru.micord.ervu_dashboard.dao;

import java.sql.Timestamp;

import org.jooq.DSLContext;
import org.springframework.stereotype.Repository;

import static ru.micord.ervu_dashboard.db_beans.public_.tables.LastRecordingDate.LAST_RECORDING_DATE;

/**
 * @author Alexandr Shalaginov
 */
@Repository
public class DataDateDao {

  private final DSLContext dslContext;

  public DataDateDao(DSLContext dslContext) {
    this.dslContext = dslContext;
  }

  public Timestamp getLastRecordingDate() {
    return dslContext.select(LAST_RECORDING_DATE.LAST_RECORDING_DATE_)
        .from(LAST_RECORDING_DATE)
        .orderBy(LAST_RECORDING_DATE.LAST_RECORDING_DATE_.desc())
        .limit(1)
        .fetchOne(LAST_RECORDING_DATE.LAST_RECORDING_DATE_);
  }
}
