package com.jasamedika.medifirst2000.dao;

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

@Repository("UraianTugasMDao")
public interface UraianTugasMDao extends PagingAndSortingRepository<UraianTugasM, Integer> {

	@Query("select model from UraianTugasM model where model.statusEnabled is true")
	List<UraianTugasM> findKinerja();

	@Query("select new Map(d.id as dokumenId,d.namaJudulDokumen as judulDokumen," + "utm.id as id,"
			+ "j.id as jabatanId,j.namaJabatan as namaJabatan,"
			+ "utm.kdProfile as kdProfile,utm.kodeExternal as kodeExternal,utm.namaExternal as namaExternal,utm.noRec as noRec,"
			+ "pt.id as pelaksanaanTugasId, pt.pelaksanaanTugas as pelaksanaanTugas,"
			+ "utm.periode as periode,utm.reportDisplay as reportDisplay,"
			+ "rk.id as rincianKegiatanId,rk.rincianKegiatan as rincianKegiatan,"
			+ "utm.statusEnabled as statusEnabled) " + "from UraianTugasM utm "
			+ "left join utm.dokumen d with d.statusEnabled is true " + "inner join utm.jabatan j "
			+ "left join utm.pelaksanaanTugas pt with pt.statusEnabled is true " + "inner join utm.rincianKegiatan rk "
			+ "where utm.statusEnabled is true " + "and j.statusEnabled is true " + "and rk.statusEnabled is true")
	List<Map<String, Object>> findListKinerja();

	@Query("select new Map(mt.id as idUraianTugas," + "pg.id as idPegawai,pg.namaLengkap as namaPegawai,"
			+ "jb.id as idJabatan,jb.namaJabatan as namaJabatan,"
			+ "rk.id as idRincian,rk.rincianKegiatan as rincianKegiatan, rk.statusVerifikasi as statusVerifikasi,"
			+ "pt.id as idPelaksanaanTugas, pt.pelaksanaanTugas as pelaksanaanTugas) "
			+ "from MapPegawaiJabatanToUnitKerja mp, UraianTugasM mt " + "left join mp.pegawai pg "
			+ "left join mp.jabatan jb " + "left join mt.rincianKegiatan rk " + "left join mt.pelaksanaanTugas pt "
			+ "where mp.jabatanId = mt.jabatanId "
			+ "and mp.statusEnabled is true and pg.statusEnabled is true and mt.statusEnabled is true "
			+ "and jb.statusEnabled is true and rk.statusEnabled is true and pt.statusEnabled is true "
			+ "and pg.id = :idPegawai " + "and jb.id = :idJabatan " + "and pt.id = :idPelaksanaanTugas "
			+ "order by rk.id")
	List<Map<String, Object>> getRincianKegiatanPegawai(@Param("idPegawai") Integer idPegawai,
			@Param("idJabatan") Integer idJabatan, @Param("idPelaksanaanTugas") Integer idPelaksanaanTugas);

}
