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

@Repository("UnitKerjaDao")
public interface UnitKerjaDao extends PagingAndSortingRepository<UnitKerjaPegawai, Integer>{
	
	@Query("select model from UnitKerjaPegawai model where model.statusEnabled is true and model.id != 0 order by model.name")
	List<UnitKerjaPegawai> getAllUnitKerja();
	
	@Query("select model from UnitKerjaPegawai model where model.statusEnabled is true and lower(model.name) like lower(:name) order by model.name")
	List<UnitKerjaPegawai> getUnitKerjaByName(@Param("name") String name);
	
	@Query("select new Map(model.id as id, model.name as name) from UnitKerjaPegawai model where model.id = :id and model.statusEnabled is true")
	Map<String, Object> getUnitKerjaById(@Param("id") Integer id);
	
	@Query("select new Map(model.id as id, model.namaUnitKerja as namaUnitKerja) from UnitKerja model where model.id = :unitKerjaId and model.statusEnabled is true")
	Map<String, Object> getUnitKerjaPegawaiById(@Param("unitKerjaId") Integer unitKerjaId);

}
