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

@Repository("ipsrsPreventiveMaintenanceDao")
public interface IpsrsPreventiveMaintenanceDao extends PagingAndSortingRepository<IpsrsPreventiveMaintenance, String>{

	@Query("select distinct NEW Map ("
			+ "a.noRec as noRec, "
			+ "a.produkId as produkId, "
			+ "a.noSeri as noSeri, "
			+ "c.kdProduk as kdProduk, "
			+ "c.namaProduk as namaProduk, "
			+ "d.merkProduk as merkProduk, "
			+ "e.typeProduk as typeProduk) "
			+ "from RegistrasiAset a "
			+ "left join a.produk c "
			+ "left join a.merkProduk d "
			+ "left join a.typeProduk e "
			+ "where a.produkId is not null")
	List<Map<String, Object>> getAsetPreventiveMaintenance();
	
	@Query("select (a.produkId) "
			+ "from PengecekanPeralatanMapping a "
			+ "where a.produkId=:produkId")
	Integer checkProdukId(
			@Param("produkId") Integer produkId);
	
	@Query("select NEW Map ("
			+ "a.id as id, "
			+ "b.bagianAlat as bagianAlat)  " 
			+ "from PengecekanPeralatanMapping a "
			+ "left join a.pengecekanPeralatan b "
			+ "where a.produkId=:produkId order by b.bagianAlat")
	List<Map<String, Object>> getBagianAlat(
			@Param("produkId") Integer produkId);
	
	@Query("select NEW Map ("
			+ "a.id as id, "
			+ "b.bagianAlat as bagianAlat)" 
			+ "from PengecekanPeralatanMapping a "
			+ "left join a.pengecekanPeralatan b "
			+ "where a.produkId=null order by b.bagianAlat")
	List<Map<String, Object>> getBagianAlat();
	
	@Query("select NEW Map ("
			+ "a.id as pegawaiId, "
			+ "a.namaLengkap as namaPegawai) "
			+ "from Pegawai a ")
	List<Map<String, Object>> getUserVerifikasi();
	
}
