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

@Repository("K3CheckListFacillitySefety")
public interface K3CheckListFacillitySefetyDao extends PagingAndSortingRepository<K3CheckListFacillitySefety, String>{

	@Query("select NEW Map ("
			+ "a.id as ruanganId, "
			+ "a.namaRuangan as namaRuangan) "
			+ "from Ruangan a")
	List<Map<String, Object>> getK3Ruangan();
	
	@Query("select NEW Map ("
			+ "a.id as id, "
			+ "a.facillityCheck as facillityCheck) "
			+ "from K3FacillityCheck a ")
	List<Map<String, Object>> getK3FacillityCheck();
	
	@Query("select NEW Map ("
			+ "a.id as id, "
			+ "a.namaKelompok as namaKelompok) "
			+ "from K3KelompokLpjGedung a "
			+ "where a.k3FacillityCheckId=:k3FacillityCheckId")
	List<Map<String, Object>> getK3KelompokLpjGedung(
			@Param("k3FacillityCheckId") Integer k3FacillityCheckId);
	
	@Query("select NEW Map ("
			+ "a.id as id, "
			+ "a.itemPeriksa as itemPeriksa) "
			+ "from K3ItemPeriksaGedung a "
			+ "where a.k3KelompokLpjGedungId=:k3KelompokLpjGedungId")
	List<Map<String, Object>> getK3ItemPeriksaGedung(
			@Param("k3KelompokLpjGedungId") Integer k3KelompokLpjGedungId);
	
	
	@Query("select NEW Map (ka.noRec as noRec, " +
			 " ka.tanggal as tanggal, r.id as id, " +
			 " r.namaRuangan as namaRuangan, " +
			 " aaa.id as idFasilitasCheck, " +
			 " aaa.facillityCheck as facillityCheck) " +
			 " from K3CheckListFacillitySefetyDetail k " +
			 " left join k.k3CheckListFacillitySefety ka " +
			 " left join k.k3ItemPeriksaGedung a " +
			 " left join a.k3KelompokLpjGedung aa " +
			 " left join aa.k3FacillityCheck aaa " +
			 " left join ka.ruangan r " +
			 " group by ka.noRec, ka.tanggal, " +
			 " r.id, r.namaRuangan, " +
			 " aaa.id, aaa.facillityCheck")
	List<Map<String, Object>> getCheckListFasilitasdanKeamanan();
	
	@Query("select NEW Map (k.noRec as noRecDetail, " +
			 " k.keterangan as keterangan, " +
			 " k.jumlah as jumlah, a.id as id, " +
			 " a.itemPeriksa as itemPeriksa) " +
			 " from K3CheckListFacillitySefetyDetail k " +
			 " left join k.k3CheckListFacillitySefety ka " +
			 " left join k.k3ItemPeriksaGedung a " +
			 " where a.k3KelompokLpjGedungId=:k3KelompokLpjGedungId and ka.noRec=:noRec")
	List<Map<String, Object>> getCheckListFasilitasdanKeamananDetail(
			@Param("k3KelompokLpjGedungId") Integer k3KelompokLpjGedungId, @Param("noRec")String noRec);
}
