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

@Repository("BakuMutuDao")
public interface BakuMutuDao extends PagingAndSortingRepository<BakuMutu, Integer> {
	
	@Query("select count(p.id) from BakuMutu p ")
	public Integer getCount();
	
	@Query("SELECT new map(p.namaBakuMutu as namaBakuMutu,p.id as id) FROM BakuMutu p WHERE p.bakuMutu is null ")
	public List<Map<String,Object>> getBakuMutuParent();
	
	@Query("SELECT new map(p.namaBakuMutu as namaBakuMutu,p.id as id) FROM BakuMutu p WHERE p.bakuMutu is not null ")
	public List<Map<String,Object>> getBakuMutuChild();
	
	@Query("SELECT new map("
			+ "p.namaBakuMutu as namaBakuMutu,"
			+ "p.id as id,"
			+ "jenisBakuMutu.jenisBakuMutu as jenisBakuMutu,"
			+ "p.kadarMaksimum as kadarMaksimum,"
			+ "satuanStandar.satuanStandar as satuanStandar"
			+ ") FROM BakuMutu p left join p.satuanStandar satuanStandar left join p.jenisBakuMutu jenisBakuMutu WHERE p.bakuMutu is not null ")
	public List<Map<String,Object>> findAllBakuMutu();
	
	@Query("SELECT new map("
			+ "p.namaBakuMutu as namaBakuMutu,"
			+ "p.id as id,"
			+ "jenisBakuMutu as jenisBakuMutu,"
			+ "p.kadarMaksimum as kadarMaksimum,"
			+ "satuanStandar as satuanStandar,"
			+ "bakuMutu as bakuMutu "
			+ ") FROM BakuMutu p left join p.satuanStandar satuanStandar left join p.jenisBakuMutu jenisBakuMutu left join p.bakuMutu bakuMutu WHERE p.id=:id ")
	public Map<String,Object> findById(@Param("id") Integer id);

}
