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 com.jasamedika.medifirst2000.entities.FasilitasM;

public interface FasilitasMDao extends PagingAndSortingRepository<FasilitasM, String> {
	
	  @Query("select new map(a.noRec as noRec, a.namaFasilitas as nmFasilitas,"
			  + " a.reportFasilitas as reportFasilitas, a.deskirpsiDetailFasilitas as deskDetailFal, "
			  + " a.pathFileGambar1 as pathGambar1, a.pathFileGambar2 as pathGambar2, "
			  + " a.pathFileGambar3 as pathGambar3, a.pathFileGambar4 as pathGambar4,  "
			  + " a.fileGambar1 as fileGambar1, a.fileGambar2 as fileGambar2, " 
			  + " a.fileGambar3 as fileGambar3,  " 
			  + " b.id as idKelas, b.namaKelas as nmKelas, c.id as idRuangan, " 
			  + " c.namaRuangan as nmRuangan, d.id as jenisProdukId, " 
			  + " d.jenisProduk as jenisProduk, e.id as idPegawaiJwb, e.namaLengkap as nmLengkapPgwJwb, "
			  + " f.id as idDept, f.namaDepartemen as nmDept) " 
			  + " from FasilitasM a left join a.kdKelas b left join a.kdRuangan c " 
			  + " left join a.kdJenisProduk d left join a.kdPegawaiPJawab e left join a.kdDepartemen f"
			  ) 
	  List<Map<String, Object>> getAllFasilitas();
	  
	  @Query("select new map(a.noRec as noRec, a.namaFasilitas as nmFasilitas,"
					  + " a.reportFasilitas as reportFasilitas, a.deskirpsiDetailFasilitas as deskDetailFal, "
					  + " a.pathFileGambar1 as pathGambar1, a.pathFileGambar2 as pathGambar2, "
					  + " a.pathFileGambar3 as pathGambar3, a.pathFileGambar4 as pathGambar4,  "
					  + " a.fileGambar1 as fileGambar1, a.fileGambar2 as fileGambar2, " 
					  + " a.fileGambar3 as fileGambar3,  " 
					  + " b.id as idKelas, b.namaKelas as nmKelas, c.id as idRuangan, " 
					  + " c.namaRuangan as nmRuangan, d.id as jenisProdukId, " 
					  + " d.jenisProduk as jenisProduk, e.id as idPegawaiJwb, e.namaLengkap as nmLengkapPgwJwb, "
					  + " f.id as idDept, f.namaDepartemen as nmDept) " 
					  + " from FasilitasM a left join a.kdKelas b left join a.kdRuangan c " 
					  + " left join a.kdJenisProduk d left join a.kdPegawaiPJawab e left join a.kdDepartemen f where b.id=:idKelas and c.id=:idRuangan"
			  ) 
	  List<Map<String, Object>> getAllFasilitasByKelasRuangan(@Param("idKelas") Integer idKelas, @Param("idRuangan") Integer idRuangan);
	 
	  @Query("select new map(a.noRec as noRec, a.namaFasilitas as nmFasilitas,"
					+ " a.reportFasilitas as reportFasilitas, a.deskirpsiDetailFasilitas as deskDetailFal, "
					+ " a.pathFileGambar1 as pathGambar1, a.pathFileGambar2 as pathGambar2, "
					+ " a.pathFileGambar3 as pathGambar3, a.pathFileGambar4 as pathGambar4,  "
					+ " a.fileGambar1 as fileGambar1, a.fileGambar2 as fileGambar2, " 
					+ " a.fileGambar3 as fileGambar3,  " 
					+ " b.id as idKelas, b.namaKelas as nmKelas, c.id as idRuangan, " 
					+ " c.namaRuangan as nmRuangan, d.id as jenisProdukId, " 
					+ " d.jenisProduk as jenisProduk, e.id as idPegawaiJwb, e.namaLengkap as nmLengkapPgwJwb, "
					+ " f.id as idDept, f.namaDepartemen as nmDept) " 
					+ " from FasilitasM a left join a.kdKelas b left join a.kdRuangan c " 
					+ " left join a.kdJenisProduk d left join a.kdPegawaiPJawab e left join a.kdDepartemen f where c.id=:idRuangan"
			  ) 
	  List<Map<String, Object>> getAllFasilitasByRuangan(@Param("idRuangan") Integer idRuangan);
	  
	  @Query("select new map(a.id as idDept, a.namaDepartemen as namaDept)from Departemen a order by a.id asc")
	  List<Map<String, Object>> getAllDepartemen();
			 

}
