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

@Repository("MappingBmhpToSetAlatDao")
public interface MappingBmhpToSetAlatDao extends PagingAndSortingRepository<MappingBmhpToSetAlat, String> {
	
	@Query("select m from MappingBmhpToSetAlat m where m.bundleSetAlat.nama=:nama ")
	List<MappingBmhpToSetAlat> findByNamaAlat(@Param("nama")  Integer nama);
	
	@Query("select new map(alat.id as idalat, alat.namaAlat as namaAlat, " +
			" satuanStandar.id as idSatuan, " +
			" satuanStandar.satuanStandar as satuanStandar, " +
			" mappingAlatToBundle.jumlah as jumlah, " +
			" mappingAlatToBundle.id as id) " +
			" from MappingBmhpToSetAlat mappingAlatToBundle "+
			" left join mappingAlatToBundle.bmhp alat " +
			" left join mappingAlatToBundle.bundleSetAlat bundleSetAlat "+
			" left join alat.satuanStandar satuanStandar " +
			" where bundleSetAlat.id=:idBundle and mappingAlatToBundle.statusEnabled in('true')")
	List<Map<String, Object>> getAlatByBundle(@Param("idBundle")Integer idBundle);

}
