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

@Repository("LevelTingkatDao")
public interface LevelTingkatDao extends PagingAndSortingRepository<LevelTingkat, Integer> {
	@Query("SELECT new map (model.id as id,model.levelTingkat as levelTingkat) "
			+ "from LevelTingkat model")
	List<Map<String,Object>> findAllLevelTingkat();
	
	@Query("select new Map(model.id as id, "
			+"model.kdLevelTingkat as kdLevelTingkat, "
			+"model.levelTingkat as levelTingkat, "
			+"model.reportDisplay as reportDisplay, "
			+"model.kdLevelTingkatHead as kdLevelTingkatHead, "
			+"departemen.id as departemenId, "
			+"departemen.namaDepartemen as namaDepartemen, "
			+"model.qLevelTingkat as qLevelTingkat, "
			+"model.kodeExternal as kodeExternal, "
			+"model.namaExternal as namaExternal, "
			+"model.statusEnabled as statusEnabled) "
			+"from LevelTingkat model "
			+"left join model.departemen departemen "
			+ "where model.id =:idLevelTingkat")
	Map<String,Object> get(@Param("idLevelTingkat") Integer idLevelTingkat);
	
	@Query("select new Map(model.id as id, model.levelTingkat as levelTingkat) from LevelTingkat model where model.id = :levelTingkatId and model.statusEnabled is true")
	Map<String,Object> getLevelTingkatById(@Param("levelTingkatId") Integer levelTingkatId);
	
	@Query("select new Map(model.id as id, "
			+"model.kdLevelTingkat as kdLevelTingkat, "
			+"model.levelTingkat as levelTingkat, "
			+"model.reportDisplay as reportDisplay, "
			+"model.kdLevelTingkatHead as kdLevelTingkatHead, "
			+"departemen.id as departemenId, "
			+"departemen.namaDepartemen as namaDepartemen, "
			+"model.qLevelTingkat as qLevelTingkat, "
			+"model.kodeExternal as kodeExternal, "
			+"model.namaExternal as namaExternal, "
			+"model.statusEnabled as statusEnabled) "
			+"from LevelTingkat model "
			+"left join model.departemen departemen ")
	List<Map<String,Object>> getAll();	
	
	@Query("select coalesce(max(model.kdLevelTingkat),0) from LevelTingkat model")
	Byte getMaxLevelTingkat();

}
