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

@Repository("MapRuanganToKelasDao")
public interface MapRuanganToKelasDao extends PagingAndSortingRepository<MapRuanganToKelas, Integer> {

	@Query("select NEW Map("
			+ "b.id as id, "
			+ "b.namaRuangan as namaRuangan) "
			+ "from MapRuanganToKelas a "
			+ "left join a.ruangan b "
			+ "left join a.kelas c "
			+ "where c.id=:id")
	List<Map<String, Object>> getRuanganByKelas(
			@Param("id") Integer id);
	
	@Query("select NEW Map("
			+ "c.id as id, "
			+ "c.namaKelas as namaKelas) "
			+ "from MapRuanganToKelas a "
			+ "left join a.ruangan b "
			+ "left join a.kelas c "
			+ "where b.id=:id")
	List<Map<String, Object>> getKelasByRuangan(
			@Param("id") Integer id);
	
	@Query("select NEW Map("
			+ "a.id as id, "
			+ "a.namaKamar as namaKamar, "
			+ "a.qtyBed as qtyBed, "
			+ "a.jumlaKamarKosong as jumlaKamarKosong, "
			+ "a.jumlaKamarIsi as jumlaKamarIsi) "
			+ "from Kamar a "
			+ "left join a.kelas b "
			+ "left join a.ruangan c "
			+ "where b.id=:kelasId and "
			+ "c.id=:ruanganId")
	List<Map<String, Object>> getKamarByKelas(
			@Param("kelasId") Integer kelasId, 
			@Param("ruanganId") Integer ruanganId);
}