package com.jasamedika.medifirst2000.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
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.DataPerusahaanYangBekerjaSama;

@Repository
public interface DataPerusahaanYangBekerjaSamaDao extends PagingAndSortingRepository<DataPerusahaanYangBekerjaSama, Integer>,JpaSpecificationExecutor {
	
	@Query("select count(p.id) from DataPerusahaanYangBekerjaSama p ")
	public Integer getCount();
	
	@Query("select p from DataPerusahaanYangBekerjaSama p where p.rekanan.jenisRekananId in (Select cast(s.nilaiField as int) from  SettingDataFixed s where s.namaField='KdPerusahaanRekanan') ")
	public List<DataPerusahaanYangBekerjaSama> getPerusahaanYangBekerjasama();
	
	@Query("select p from DataPerusahaanYangBekerjaSama p where p.rekanan.jenisRekananId in (Select cast(s.nilaiField as int) from  SettingDataFixed s where s.namaField='KdAsuransiRekanan') ")
	public List<DataPerusahaanYangBekerjaSama> getAsuransiYangBekerjasama();
	
	@Query("select p from DataPerusahaanYangBekerjaSama p where p.rekanan.jenisRekananId in (Select cast(s.nilaiField as int) from  SettingDataFixed s where s.namaField='KdRumahSakitRekanan') ")
	public List<DataPerusahaanYangBekerjaSama> getRumahSakitYangBekerjasama();
	
	@Query("select p from DataPerusahaanYangBekerjaSama p where p.rekanan.jenisRekananId in (Select cast(s.nilaiField as int) from  SettingDataFixed s where s.namaField='KdYayasanRekanan') ")
	public List<DataPerusahaanYangBekerjaSama> getYayasanYangBekerjasama();
	
	@Query("select p from DataPerusahaanYangBekerjaSama p where p.rekanan.id=:id ")
	public DataPerusahaanYangBekerjaSama getByIdRekanan(@Param("id") Integer id);
	
	@Query("select new map(p.noPks as noPks,"
			+ " p.rekananId as rekananId,"
			+ " p.rekanan.namaRekanan as namaRekanan,"
			+ " p.noRec as noRec,"
			+ " p.anakPerusahaan as anakPerusahaan,"
			+ " p.jumlahKaryawan as jumlahKaryawan,"
			+ " p.plafon as plafon,"
			+ " p.caraPenagihan as caraPenagihan,"
			+ " p.alamatPenagihan as alamatPenagihan,"
			+ " p.contactPerson as contactPerson,"
			+ " p.jangkaAwal as jangkaAwal,"
			+ " p.jangkaAkhir as jangkaAkhir,"
			+ " p.namaFilePks as namaFilePks,"
			+ " p.noTelpFax as noTelpFax,"
			+ " p.email as email,"
			+ " p.pathFile as pathFile)"
			+ " from DataPerusahaanYangBekerjaSama p "
			+ "where p.rekanan.jenisRekananId = 7 "
			+ "and p.statusEnabled is true")
	public List<DataPerusahaanYangBekerjaSama> getRumahSakitYangBekerjaSama();
	
	@Query("select new map(p.noPks as noPks,"
			+ " p.rekananId as rekananId,"
			+ " p.rekanan.namaRekanan as namaRekanan,"
			+ " p.noRec as noRec,"
			+ " p.anakPerusahaan as anakPerusahaan,"
			+ " p.jumlahKaryawan as jumlahKaryawan,"
			+ " p.plafon as plafon,"
			+ " p.caraPenagihan as caraPenagihan,"
			+ " p.alamatPenagihan as alamatPenagihan,"
			+ " p.contactPerson as contactPerson,"
			+ " p.jangkaAwal as jangkaAwal,"
			+ " p.jangkaAkhir as jangkaAkhir,"
			+ " p.namaFilePks as namaFilePks,"
			+ " p.noTelpFax as noTelpFax,"
			+ " p.email as email,"
			+ " p.pathFile as pathFile)"
			+ " from DataPerusahaanYangBekerjaSama p "
			+ "where p.rekanan.jenisRekananId = 6 "
			+ "and p.statusEnabled is true")
	public List<DataPerusahaanYangBekerjaSama> getYayasanYangBekerjaSama();
}
