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.Kalender;
import com.jasamedika.medifirst2000.entities.MapKalenderToHariLibur;

@Repository
public interface MapKalenderToHariLiburDao extends PagingAndSortingRepository<MapKalenderToHariLibur, Integer> {
	
	@Query("select new map (model.id as id, model.namaExternal as name, model.tanggal.tanggal as tanggal) from MapKalenderToHariLibur model where model.statusEnabled is true")
	public List<Map<String, Object>> getAllByStatusEnabled();
	
	@Query("select model from Kalender model where model.statusEnabled is true and to_char(tanggal,'yyyy-MM-dd') = :tanggal")
	public Kalender getKalender(@Param("tanggal") String tgl);
	
	@Query("select to_char(kalender.tanggal,'yyyy-MM-dd') "+
			"from MapKalenderToHariLibur mapLibur "+
			"inner join mapLibur.tanggal kalender "+
			"inner join mapLibur.hariLibur hariLibur "+
			"where hariLibur.id in (8,17) "+
			"and to_char(kalender.tanggal,'yyyy')=:tahun "+
			"and mapLibur.statusEnabled is true")
	public List<String> getTglCutiBersama(@Param("tahun") String tahun);
	
	@Query("select new Map(model.statusEnabled as statusEnabled,model.namaExternal as namaExternal,"
			+ "to_char(kalender.tanggal,'dd-MM-yyyy') as tanggal,to_char(kalender.tanggal,'yyyy-MM-dd') as tanggalId,"
			+ "model.reportDisplay as reportDisplay,model.id as id,model.kodeExternal as kodeExternal,"
			+ "hariLibur.id as hariLiburId,hariLibur.namaHariLibur as hariLiburName,"
			+ "model.noRec as noRec) "
			+ "from MapKalenderToHariLibur model "
			+ "inner join model.tanggal kalender "
			+ "inner join model.hariLibur hariLibur "
			+ "where model.statusEnabled is true "
			+ "and to_char(kalender.tanggal,'yyyy')>=:tahun")
	public List<Map<String, Object>> getMappingHariLibur(@Param("tahun") String tahun);
}
