package com.jasamedika.medifirst2000.dao;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.jasamedika.medifirst2000.entities.ActivityPegawai;

/**
 * Repository class for PelayananPasien
 * 
 * @author Generator
 */
@Repository("ActivityPegawaiDao")
public interface ActivityPegawaiDao extends PagingAndSortingRepository<ActivityPegawai, String> {

	@Query("select p from ActivityPegawai p where date(p.tanggalKejadian)=date(:tanggal) ")
	Integer countToday(@Param("tanggal") Date tanggal);

	@Query("select p from ActivityPegawai p order by p.tanggalKejadian desc ")
	List<ActivityPegawai> findDescending();

	@Query("select p from ActivityPegawai p where date(p.tanggalKejadian)>=date(:start)  and   date(p.tanggalKejadian)<=date(:until)  order by p.tanggalKejadian desc ")
	List<ActivityPegawai> findDescending(@Param("start") Date start, @Param("until") Date until, Pageable page);

	String strQryActivity = "select new Map(ap.keterangan as keterangan," + "ap.tanggalKejadian as tanggalKejadian,"
			+ "ap.pegawaiId as pegawaiId," + "ap.group as group," + "ap.statusEnabled as statusEnabled,"
			+ "ap.noRec as noRec) " + "from ActivityPegawai ap ";

	String activityHariIni = "where to_char(ap.tanggalKejadian,'yyyy-MM-dd') = to_char(current_date,'yyyy-MM-dd')";

	String activityTanggal = "where to_char(ap.tanggalKejadian,'yyyy-MM-dd') = :tanggal";

	String activityTanggalPegawai = "where to_char(ap.tanggalKejadian,'yyyy-MM-dd') = :tanggal "
			+ "and ap.pegawaiId = :idPegawai";

	@Query(strQryActivity + activityHariIni)
	List<Map<String, Object>> aktivitasHariIni();

	@Query(strQryActivity + activityTanggal)
	List<Map<String, Object>> aktivitasByDate(@Param("tanggal") String tanggal);

	@Query(strQryActivity + activityTanggalPegawai)
	List<Map<String, Object>> aktivitasByDatePegawai(@Param("tanggal") String tanggal,
			@Param("idPegawai") Integer idPegawai);

}
