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

/**
 * Repository class for Departemen
 * 
 * @author Roberto
 */
@Repository("DepartemenDao")
public interface DepartemenDao extends PagingAndSortingRepository<Departemen, Integer> {
	// custom query WITH pagination
		/*@Query("select model from Departemen model where model.namaDepartemen=:value")
		public Page<Departemen> findPageDepartemenByNama(@Param("key") String key,@Param("operator") String operator,@Param("value") String value,Pageable Page);*/
		
	@Query("select model from Departemen model where model.id=:id")
	Departemen findById(@Param("id") Integer id);
	
	@Query("select new Map (departemen.id as id , departemen.namaDepartemen as namaDepartemen) from Departemen departemen left join departemen.jenisPerawatan jp where jp.id in (5,6)")
	public List<Map<String,Object>> findAllDepartemeById5And6();
	
	@Query("select new Map (departemen.id as id , departemen.namaDepartemen as namaDepartemen) from Departemen departemen")
	public List<Map<String,Object>> findAllDepartemen();
	
	@Query("select new Map(model.id, model.namaDepartemen, model.jenisPerawatanId, model.pegawaiKepalaId) "
			+ "from Departemen model where model.id = :departemenId and model.statusEnabled is true")
	public Map<String,Object> getDepartemenById(@Param("departemenId") Integer departemenId);

}
