package com.jasamedika.medifirst2000.dao;

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

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

/**
 * @author salmanoe
 * @since Dec 31, 2021
 */
@Repository("mapProfesiJabatanDao")
public interface MapJabatanProfesiDao extends PagingAndSortingRepository<MapJabatanProfesi, Integer> {

	@Query("select new Map(mjp.id as id," + "prf.id as profesiId,prf.namaProfesi as profesi,"
			+ "jb.id as jabatanId,(jb.id || ' - ' ||jb.namaJabatan) as jabatan) " + "from MapJabatanProfesi mjp "
			+ "inner join mjp.profesi prf " + "inner join mjp.jabatan jb " + "where mjp.statusEnabled is true "
			+ "order by jb.namaJabatan, jb.id, prf.namaProfesi")
	List<Map<String, Object>> findMapping();

	@Query(value = "select mjp.* from sdm_mapjabatanprofesi_m mjp where mjp.jabatanfk = :jabatanId limit 1", nativeQuery = true)
	Optional<MapJabatanProfesi> findByJabatan(@Param("jabatanId") Integer idJabatan);

}
