package com.dbnt.kcscbackend.admin.dashboard.repository;

import com.dbnt.kcscbackend.admin.dashboard.entity.TnDailyUserLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDate;
import java.util.List;

public interface TnDailyUserLogRepository extends JpaRepository<TnDailyUserLog, Long> {
    List<TnDailyUserLog> findByLogDtBetweenOrderByLogDt(LocalDate startDate, LocalDate endDate);

    @Query(value = "SELECT TO_CHAR(log_dt, 'YYYYMM') as log_dt, "
            + "SUM(log_cnt) as log_cnt "
            + "FROM tn_daily_user_log "
            + "WHERE log_dt BETWEEN :startDate AND :endDate "
            + "GROUP BY TO_CHAR(log_dt, 'YYYYMM') "
            + "ORDER BY log_dt", nativeQuery = true)
    List<Object[]> selectMonthlyUserLogStatistics(@Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate);

}
