package com.jasamedika.medifirst2000.dao;

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

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.PegawaiHistoriEvaluasiKomponen;;

@Repository("RiwayatPenilaianKompetensiPegawai")
public interface RiwayatPenilaianKompetensiPegawaiDao
		extends PagingAndSortingRepository<PegawaiHistoriEvaluasiKomponen, String> {

	@Query("select new map (komponenEvaluasi.reportDisplay as kompetensi, "
			+ "komponenEvaluasi.nilaiStandar as nilaiStandar,komponenEvaluasi.id as idKomponenEvaluasi, "
			+ "jabatan.id as idJabatan, " + "kelompokEvaluasi.id as idKelompokEvaluasi, "
			+ "kelompokEvaluasi.kelompokEvaluasi as kelompokEvaluasi, "
			+ "komponenEvaluasi.deskripsiKompetensi as deskripsiKompetensi ) "
			+ "from KomponenEvaluasi komponenEvaluasi " + "left join komponenEvaluasi.jabatan jabatan "
			+ "left join komponenEvaluasi.kelompokEvaluasi kelompokEvaluasi "
			+ "left join komponenEvaluasi.departemen departemen " + "where jabatan.id = :idjabatan")
	List<Map<String, Object>> getPenilaianKompetensiRiwayat(@Param("idjabatan") Integer idjabatan);

	@Query("select new map (komponenEvaluasi.komponenEvaluasi as kompetensi, "
			+ "komponenEvaluasi.nilaiStandar as nilaiStandar, " + "jabatan.id as jabatanId, "
			+ "komponenEvaluasi.id as idKomponenEvaluasi, " + "jabatan.namaJabatan as namaJabatan, "
			+ "kelompokEvaluasi.id as idKelompokEvaluasi, " + "kelompokEvaluasi.kelompokEvaluasi as jenisKompetensi) "
			+ "from KomponenEvaluasi komponenEvaluasi " + "left join komponenEvaluasi.jabatan jabatan "
			+ "left join komponenEvaluasi.kelompokEvaluasi kelompokEvaluasi " + "where jabatan.id = :idjabatan "
			+ "order by kelompokEvaluasi.id ")
	List<Map<String, Object>> getKompetensiByRuangan(@Param("idjabatan") Integer idjabatan);

	@Query("select new map (pegawaiHistoriEvaluasiKomponen.noRec as idPegawaiHistoriEvaluasiKomponen, "
			+ "pegawaiHistoriEvaluasiKomponen.nilaiHasilEvaluasi as nilaiHasilEvaluasi, "
			+ "komponenEvaluasi.id as idKomponenEvaluasi, " + "komponenEvaluasi.nilaiStandar as nilaiStandar, "
			+ "komponenEvaluasi.komponenEvaluasi as kompetensi, " + "pegawai.id as idpegawai, "
			+ "strukHistory.noRec as noRecStrukHistory, "
			+ "pegawaiHistoryEvaluasi.noRec as noRecPegawaiHistoryEvaluasi, "
			+ "pegawaiHistoryEvaluasi.rekomendasi as rekomendasi, " + "strukHistory.tglHistori as tglHistory, "
			+ "ruangan.id as idRuangan) " + "from PegawaiHistoriEvaluasiKomponen pegawaiHistoriEvaluasiKomponen "
			+ "left join pegawaiHistoriEvaluasiKomponen.komponenEvaluasi komponenEvaluasi "
			+ "left join pegawaiHistoriEvaluasiKomponen.pegawai pegawai "
			+ "left join pegawaiHistoriEvaluasiKomponen.strukHistory strukHistory "
			+ "left join strukHistory.ruangan ruangan "
			+ "left join strukHistory.pegawaiHistoriEvaluasi pegawaiHistoryEvaluasi "
			+ "where pegawai.id = :idPegawai and strukHistory.tglHistori between :start and :end "
			+ "and komponenEvaluasi.id =:idKomponen")
	Map<String, Object> getKompetensiByPegawai(@Param("idPegawai") Integer idPegawai, @Param("start") Date start,
			@Param("end") Date end, @Param("idKomponen") Integer idKomponen);

	@Query("select new map( " + "kelompokEvaluasi.kelompokEvaluasi as title, "
			+ "kelompokEvaluasi.id as idKelompokEvaluasi) " + "from KelompokEvaluasi kelompokEvaluasi "
			+ "where kelompokEvaluasi.id between 1 and 4")
	List<Map<String, Object>> getKelompokEvaluasi();

	@Query("select new map(pendidikan.namaPendidikan as namaPendidikan, " + " pegawai.tglMasuk as tglMasuk)"
			+ " from MapPegawaiJabatanToUnitKerja mapPegawai " + "left join mapPegawai.pegawai pegawai "
			+ "left join pegawai.pendidikan pendidikan " + "left join mapPegawai.jabatan jabatanInternal "
			+ "where mapPegawai.isPrimary is true " + "and mapPegawai.statusEnabled is true "
			+ "and jabatanInternal.id = :idJabatan")
	Map<String, Object> getPendidikan(@Param("idJabatan") Integer idJabatan);

	@Query("select new map(pegawaiHistoriEvaluasiKomponen.nilaiHasilEvaluasi as nilaiHasilEvaluasi, "
			+ "pegawaiHistoriEvaluasi.rekomendasi as rekomendasi, "
			+ "to_char(strukHistori.tglHistori, 'yyyy-MM-dd') as tglHistory) " + "from StrukHistori strukHistori "
			+ "left join strukHistori.pegawaiHistoriEvaluasi pegawaiHistoriEvaluasi "
			+ "left join strukHistori.pegawaiHistoriEvaluasiKomponen pegawaiHistoriEvaluasiKomponen "
			+ "left join pegawaiHistoriEvaluasiKomponen.pegawai pegawai " + "where pegawai.id = :idPegawai "
			+ "order by to_char(strukHistori.tglHistori, 'yyyy-MM-dd') desc ")
	List<Map<String, Object>> getPenilaian(@Param("idPegawai") Integer idPegawai);

	@Query("select new map(pegawai.namaLengkap as namaLengkap, " + "pegawai.nipPns as nip, "
			+ "ruangan.namaRuangan as unitKerja, " + "jabatanInternal.namaJabatan as jabatanInternal, "
			+ "to_char(strukHistori.tglHistori,'yyyy-MM-dd') as tglPenilaian, "
			+ "kategoryPegawai.detailKategoryPegawai as statusKepegawaian, "
			+ "pegawaiHistoriEvaluasiKomponen.nilaiHasilEvaluasi as nilaiHasilEvaluasi, "
			+ "pegawaiHistoriEvaluasi.rekomendasi as rekomendasi, " + "pegawai.id as idPegawai) "
			+ "from StrukHistori strukHistori, MapPegawaiJabatanToUnitKerja mapPegawai "
			+ "left join strukHistori.pegawaiHistoriEvaluasi pegawaiHistoriEvaluasi "
			+ "left join strukHistori.pegawaiHistoriEvaluasiKomponen pegawaiHistoriEvaluasiKomponen "
			+ "left join pegawaiHistoriEvaluasiKomponen.pegawai pegawai " + "left join pegawai.ruangan ruangan "
			+ "left join mapPegawai.jabatan jabatanInternal "
			+ "left join pegawai.detailKategoryPegawai kategoryPegawai " + "where mapPegawai.pegawaiId = pegawai.id "
			+ "and mapPegawai.isPrimary is true " + "and mapPegawai.statusEnabled is true")
	List<Map<String, Object>> getRencanaTindakLanjut();

}
