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

@Repository("mappingCycleDao")
public interface MappingCycleDao extends PagingAndSortingRepository<MappingCycle, String> {
	@Query("select new map(a.noRec as noRec, " +
			" a.jumlah as jumlah, " +
			" c.id as idSatuan, c.namaExternal as satuan, " +
			" d.id as idBahan, d.namaExternal as namaBahan) from MappingCycleLaundry a " +
			" left join a.mappingCycle b " +
			" left join a.satuan c" +
			" left join a.namaBahan d " +
			" where b.noRec=:noRec and a.statusEnabled in('true')")
	List<Map<String, Object>> getMappingCycleNamaBahan(@Param("noRec")String noRec);
	
	@Query("select new map(a.noRec as noRec, " +
			" b.id as idJenisLinen, " +
			" b.jenisLinen as jenisLinen, " +
			" c.id as idMesin, " +
			" c.namaExternal as namaMesin, " +
			" c.kapasitas as kapasitas, " +
			" d.id as idProsesCuci, " +
			" d.prosesCuci as prosesCuci) from MappingCycle a " +
			" left join a.jenisLinen b " +
			" left join a.mesin c " +
			" left join a.prosesCuci d where a.statusEnabled in('true')") 
	List<Map<String, Object>> getMappingCycle();
	
	@Query("select new map(a.noRec as noRec, " +
			" b.id as idJenisLinen, " +
			" b.jenisLinen as jenisLinen, " +
			" c.id as idMesin, " +
			" c.namaExternal as namaMesin, " +
			" c.kapasitas as kapasitas, " +
			" d.id as idProsesCuci, " +
			" d.prosesCuci as prosesCuci) from MappingCycle a " +
			" left join a.jenisLinen b " +
			" left join a.mesin c " +
			" left join a.prosesCuci d " +
			" where a.noRec=:noRec and a.statusEnabled in('true')") 
	List<Map<String, Object>> getMappingCycleByNoRec(@Param("noRec")String noRec);
	
	@Query("select new map(a.noRec as noRec, " +
			" a.jumlah as jumlah, " +
			" c.id as idSatuan, c.namaExternal as satuan, " +
			" d.id as idBahan, d.namaExternal as namaBahan) from MappingCycleLaundry a " +
			" left join a.mappingCycle b " +
			" left join a.satuan c" +
			" left join a.namaBahan d " +
			" where b.noRec=:noRec and a.statusEnabled in('true')")
	List<Map<String, Object>> getMappingCycleNamaBahanByNoRec(@Param("noRec")String noRec);
	

}
