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

/**
 * Repository class for ShiftKerja
 * 
 * @author Generator
 */
@Repository("ShiftKerjaDao")
public interface ShiftKerjaDao extends PagingAndSortingRepository<ShiftKerja, Integer> {

	@Query("select new Map(model.factorRate as factorRate, " + "model.flagKetidakhadiran as flagKetidakhadiran, "
			+ "model.id as id, " + "model.jadwalPraktekId as jadwalPraktekId, "
			+ "model.jamBreakAkhir as jamBreakAkhir, " + "model.jamBreakAwal as jamBreakAwal, "
			+ "model.jamMasuk as jamMasuk, " + "model.jamPraktekId as jamPraktekId, " + "model.jamPulang as jamPulang, "
			+ "model.kdProfile as kdProfile, " + "model.kdShift as kdShift, "
			+ "model.kelompokShiftId as kelompokShiftId, " + "model.kodeExternal as kodeExternal, "
			+ "model.komponenIndexId as komponenIndexId, " + "model.namaExternal as namaExternal, "
			+ "model.namaShift as namaShift, " + "model.noRec as noRec, "
			+ "model.operatorFactorRate as operatorFactorRate, " + "model.qShift as qShift, "
			+ "model.reportDisplay as reportDisplay, " + "model.statusEnabled as statusEnabled, "
			+ "model.waktuIstirahat as waktuIstirahat) " + "from ShiftKerja model "
			+ "where model.kelompokShift.id=:id " + "and model.statusEnabled is true")
	List<Map<String, Object>> findByKelompokShiftId(@Param("id") Integer idShift);

	@Query(" select new map (komponenIndex.komponenIndex as namaKomponen, " + " komponenIndex.id as idKomponenIndex) "
			+ " from KomponenIndex komponenIndex")
	public List<Map<String, Object>> getListKomponenIndex();

	@Query(" select new map (shiftKerja.factorRate as factorRate, " + "shiftKerja.id as idShiftKerja, "
			+ "shiftKerja.waktuIstirahat as waktuIstirahat, " + "shiftKerja.namaExternal as namaExternal, "
			+ "shiftKerja.reportDisplay as reportDisplay, " + "shiftKerja.jamBreakAwal as jamBreakAwal, "
			+ "shiftKerja.jamBreakAkhir as jamBreakAkhir, " + "shiftKerja.jamMasuk as jamMasuk, "
			+ "shiftKerja.jamPulang as jamPulang, " + "shiftKerja.kodeExternal as kodeExternal, "
			+ "shiftKerja.namaShift as namaShift, " + "shiftKerja.operatorFactorRate as operatorFactorRate, "
			+ "kelompokShift.id as idkelompokShift, " + "kelompokShift.name as namaKelompokShift, "
			+ "komponenIndex.id as idkomponenIndex, " + "komponenIndex.komponenIndex as komponenIndex,"
			+ "shiftKerja.flagKetidakhadiran as flagKetidakhadiran," + "shiftKerja.statusEnabled as statusEnabled) "
			+ "from ShiftKerja shiftKerja " + "left join shiftKerja.komponenIndex komponenIndex "
			+ "left join shiftKerja.kelompokShift kelompokShift " + "where shiftKerja.statusEnabled is true")
	public List<Map<String, Object>> getListShiftKerja();

	@Query("select new Map(model.id as id,model.kodeExternal as kodeExternal,model.kelompokShiftId as kelompokShiftId,model.flagKetidakhadiran as flagKetidakhadiran) "
			+ "from ShiftKerja model " + "where lower(model.kodeExternal) in (:listKdShift) "
			+ "and model.statusEnabled is true " + "and model.flagKetidakhadiran is false")
	List<Map<String, Object>> getListShiftKerja(@Param("listKdShift") List<String> listKdShift);

	@Query("select distinct new Map(s.kodeExternal as kodeExternal, " + "s.namaShift as namaShift, "
			+ "s.jamMasuk as jamMasuk, " + "s.jamPulang as jamPulang) " + "from ShiftKerja s "
			+ "where s.statusEnabled is true " + "order by s.kodeExternal")
	public List<Map<String, Object>> getListKetShift();

	@Query("select sk.id from ShiftKerja sk where sk.statusEnabled is true and sk.jamMasuk = '' and sk.jamPulang = ''")
	public List<Integer> findListNonjadwal();

}
