package com.jasamedika.medifirst2000.dao;

import java.util.List;
import java.util.Map;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.jasamedika.medifirst2000.entities.KeluargaPegawai;

/**
 * Repository class for Pegawai
 * 
 * @author Lukman Hakim (lukman.uki@gmail.com)
 * @Date 31 Januari 2017
 */
@Repository("KeluargaPegawaiDao")
public interface KeluargaPegawaiDao extends
		CrudRepository<KeluargaPegawai, Integer>,
		JpaSpecificationExecutor<KeluargaPegawai> {
	@Query("select model from KeluargaPegawai model where model.id=:key")
	public KeluargaPegawai findById(@Param("key") Integer key);

/*	@Query("select new Map ( kg) from KeluargaPegawai kg left join kq.pegawai kqp where kgp.id=:idPegawai and kgp.namaLengkap like :namaPegawai")
	public List<Map<String, Object>> findAllDataKeluargaById(@Param("idPegawai") Integer idPegawai, @Param("namaPegawai") String namaPegawai );
*/
	@Query("select new Map ( "
			+ "   "
			+ "kg.id as id, "
			+ " kg.tglLahir as tglLahir, "
			+ "kg.namaLengkap as namaLengkap, "
			+ "st.name as tanggungan, "
			+ " pk.pekerjaan as namaPekerjaan, hk.hubunganKeluarga as hubunganKeluarga )  "
			+ "from "
			+ "KeluargaPegawai kg "
			+ "left join kg.pegawai p "
			+ "left join kg.statusTanggungan st "
			+ " left join kg.pekerjaan pk "
			+ " left join kg.hubunganKeluarga hk "
			+ "where p.id=:id order by kg.id asc  ")
	public List<Map<String, Object>> findAllDataKeluarga(@Param("id") Integer id);
}
