package com.jasamedika.medifirst2000.dao;

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

@Repository("PlanningDiklatHumasMarketPesertaDao")
public interface PlanningDiklatHumasMarketPesertaDao extends PagingAndSortingRepository<PlanningDiklatHumasMarketPeserta, String>{
	@Query("select new map(a.noPlanning as noPlanning, a.noRec as noRecPeserta, h.noRec as noRecDHM, a.tglPlanning as tglPlanning, "  +
			" a.deskripsiTugasFungsi as deskripsiTugasFungsi, a.kdProdukDHM as kdProdukDHM, " +
			" a.deskripsiTugasFungsi as dekripsiTugasFungsi, a.namaRekananPeserta as namaRekananPeserta, " +
			" a.isPetugasPePJawab as isPetugasPeJawab, a.keteranganPlanLainnya as ketPlanLain, " +
			" a.keteranganExecLainnya as ketExecLain," +
			" a.statusEnabled as statusEnabled, b.id as jenisPetugasPeId, " +
			" b.jenisPetugasPe as jenisPetugasPe, " +
			" d.id as rekananId, d.namaRekanan as namaRekanan, " +
			" e.id as asalPesertaId, e.asalPeserta as asalPeserta, f.id as pegawaiExeId, " +
			" f.namaLengkap as namaLengkapExe, g.id as pegawaiId, g.namaLengkap as namaPegawai) " +
			" from PlanningDiklatHumasMarketPeserta a " +
			" left join a.kdJenisPetugasPe b " +
			" left join a.kdRekananPeserta d " +
			" left join a.kdAsalPeserta e " +
			" left join a.kdPegawaiExec f " +
			" left join a.kdPegawai g, PlanningDiklatHumasMarket h " +
			" where a.noPlanning=:noPlanning and a.noPlanning = h.noPlanning and a.kdProdukDHM = h.kdProdukDHM")
	List<Map<String, Object>> getListPlanningDHMPesertaByNoPlanning(@Param("noPlanning") String noPlanning);
	
	@Query("select new map(a.id as produkAsalId, a.asalProduk as asalProduk) from AsalProduk a order by a.id asc")
	List<Map<String, Object>> getListProdukAsal(Pageable pageable);
	
	@Query("select new map(a.id as id, a.jenisPetugasPe as jenisPetugasPe) from JenisPetugasPelaksana a order by a.id asc")
	List<Map<String, Object>> getListJenisPetugasPe(Pageable pageable);
	
	@Query("select new map(a.id as id, a.asalPeserta as asalPeserta) from AsalPeserta a order by a.id asc")
	List<Map<String, Object>> getListAsalPeserta(Pageable pageable);
	
	@Query("select new map(a.id as id, a.namaRekanan as namaRekanan) from Rekanan a order by a.id asc")
	List<Map<String, Object>> getListRekananPeserta(Pageable pageable);
	
	@Query("select new map(a.noplanning as noPlanning, a.namaplanning as namaPlanning, " +
			" a.deskripsiplanning as deskripsi, a.tglpegajuan as tglPengajuan) from StrukPlanning a where noplanning like 'HM%'")
	List<Map<String, Object>> getListAllPlanningDHM();
	
	@Query("select new map(a.id as idpegawai, a.namaLengkap as namaLengkap) from Pegawai a order by a.id asc")
	List<Map<String, Object>> getListPegawai(Pageable pageable);
	
	@Query("select new map(a.noPlanning as noPlanning, a.kdProdukDHM as produkDHM) from PlanningDiklatHumasMarket a where a.noPlanning=:noPlanning")
	List<Map<String, Object>> getListProdukDHMbyNoPlanning(@Param("noPlanning") String noPlanning);
	
	@Query("select new map(a.noPlanning as noPlanning,a.noRec as noRec, "
			+ " b.id as jenisPetugasPeId, " +
			"  b.jenisPetugasPe as jenisPetugasPe, " +
			"  g.id as pegawaiId, g.namaLengkap as namaPegawai,"
			+ " g.alamat as alamat, g.noTlp as noTlp, g.email as email ) " +
			" from PlanningDiklatHumasMarketPeserta a " +
			" left join a.kdJenisPetugasPe b " +
			" left join a.kdPegawai g "
			+ " where a.noPlanning=:noPlanning "
			+ " and b.id = :idJenisPetugas")
	List<Map<String, Object>> getListPlanningDHMPesertaHukorByNoPlanning(@Param("noPlanning") String noPlanning,@Param("idJenisPetugas") Integer idJenisPetugas);
	
	@Query("select new map(a.noPlanning as noPlanning,a.noRec as noRec, "
			+ " b.id as jenisPetugasPeId, " +
			"  b.jenisPetugasPe as jenisPetugasPe, " +
			"  g.id as pegawaiId, g.namaLengkap as namaPegawai,"
			+ " g.alamat as alamat, g.noTlp as noTlp, g.email as email ) " +
			" from PlanningDiklatHumasMarketPeserta a " +
			" left join a.kdJenisPetugasPe b " +
			" left join a.kdPegawai g "
			+ " where a.noPlanning=:noPlanning ")
	List<Map<String, Object>> getListPlanningDHMPesertaHukorByNoPlanning(@Param("noPlanning") String noPlanning);
	
	
}
