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

/**
 * @author salmanoe
 * @since Oct 8, 2021
 */
@Repository("profesiDao")
public interface ProfesiDao extends PagingAndSortingRepository<Profesi, Integer> {
	
	@Query("select prf from Profesi prf where prf.statusEnabled is true order by prf.namaProfesi asc")
	public List<Profesi> findAllActive();

	String strAllActive = "select new Map(prf.id as id,prf.namaProfesi as namaProfesi) from Profesi prf where prf.statusEnabled is true";

	String whrJenis = " and prf.jenisProfesi = :jenisId";

	String srtNama = " order by prf.namaProfesi";

	@Query(strAllActive + srtNama)
	public List<Map<String, Object>> findByStatus();

	@Query(strAllActive + whrJenis + srtNama)
	public List<Map<String, Object>> findByStatus(@Param("jenisId") Short idJenis);

	String strAllJabatanActive = "select new Map(prf.id as id,prf.namaProfesi as namaProfesi) "
			+ "from MapPegawaiJabatanToUnitKerja mj, MapJabatanProfesi mjp " + "inner join mjp.profesi prf "
			+ "where mj.jabatanId = mjp.jabatanId " + "and mj.statusEnabled is true " + "and prf.statusEnabled is true";

	String whrPegawai = " and mj.pegawaiId = :pegawaiId";

	@Query(strAllJabatanActive + whrPegawai + srtNama)
	public List<Map<String, Object>> findByStatus(@Param("pegawaiId") Integer idPegawai);

	@Query(strAllJabatanActive + whrPegawai + whrJenis + srtNama)
	public List<Map<String, Object>> findByStatus(@Param("pegawaiId") Integer idPegawai,
			@Param("jenisId") Short idJenis);

}
