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

@Repository("IndikatorBIOSDao")
public interface IndikatorBIOSDao extends PagingAndSortingRepository<IndikatorBIOS, Integer> {

	@Query("select indikatorBIOS from IndikatorBIOS indikatorBIOS where indikatorBIOS.indikator =:indikator")
	IndikatorBIOS findByIdIndikatorBIOS(@Param("indikator") String indikator);

	@Query("select new Map(model.id as id,model.statusEnabled as statusEnabled,model.indikator as indikator,model.uraian as uraian) "
			+ "from IndikatorBIOS model where model.statusEnabled is true order by model.indikator")
	List<Map<String, Object>> findAllCustom();

	@Query("select new Map(ib.id as id,ib.uraian as indikator) "
			+ "from IndikatorBIOS ib where ib.statusEnabled is true and ib.indikator not in (:listKdIndikator) and ib.nmrumpun = 'Kesehatan'")
	List<Map<String, Object>> listIndikatorLainnya(@Param("listKdIndikator") List<String> listKdIndikator);

	String strQryKeuangan = "select new Map(ib.id as id,ib.uraian as indikator) "
			+ "from IndikatorBIOS ib where ib.statusEnabled is true";

	String penerimaan = " and ib.nmrumpun = 'Penerimaan'";

	String pengeluaran = " and ib.nmrumpun = 'Pengeluaran'";

	@Query(strQryKeuangan + penerimaan)
	List<Map<String, Object>> listIndikatorPenerimaanKeuangan();

	@Query(strQryKeuangan + pengeluaran)
	List<Map<String, Object>> listIndikatorPengeluaranKeuangan();

	@Query("select ib.indikator from IndikatorBIOS ib where ib.statusEnabled is true and ib.indikator not in (:listKdIndikator) and ib.nmrumpun = 'Kesehatan'")
	List<String> listKdIndikatorLainException(@Param("listKdIndikator") List<String> listKdIndikator);

	String strQryKdAkun = "select ib.indikator from IndikatorBIOS ib where ib.statusEnabled is true";

	@Query(strQryKdAkun + penerimaan)
	List<String> listKdAkunPenerimaanKeuangan();

	@Query(strQryKdAkun + pengeluaran)
	List<String> listKdAkunPengeluaranKeuangan();

}
