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

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

import java.util.List;

public interface ApiKeyRepository extends JpaRepository<TnApiKey, String> {
    List<TnApiKey> findAllByOrderByEndDtDesc();

    @Query(value = "SELECT TO_CHAR(access_dt, 'YYYY-MM-DD') as log_dt, count(1) as log_cnt "
            + "FROM th_api_log "
            + "WHERE access_id = :UserId "
            + "GROUP BY TO_CHAR(access_dt, 'YYYY-MM-DD') "
            + "ORDER BY log_dt asc", nativeQuery = true)
    List<Object[]> selectCountApiDaily(@Param("UserId") String UserId);
}
