package com.jasamedika.medifirst2000.dao;

import java.util.List;
import java.util.Optional;

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

@Repository("HargaNettoProdukByKelasDDao")
public interface HargaNettoProdukByKelasDDao extends PagingAndSortingRepository<HargaNettoProdukByKelasD, Integer> {
	@Query("select model from HargaNettoProdukByKelasD model where model.produk.id=:produkId and model.kelas.id=:kelasId "
			+ "and model.asalProduk.id=:asalProdukId and model.jenisTarif.id=:jenisTarifId")
	public List<HargaNettoProdukByKelasD> findProdByKelas(@Param("produkId") Integer produkId,
			@Param("kelasId") Integer kelasId, @Param("asalProdukId") Integer asalProdukId,
			@Param("jenisTarifId") Integer jenisTarifId);

	@Query("select a from HargaNettoProdukByKelasD a " + "left join a.kelas b " + "left join a.produk d "
			+ "where b.id=:kelasId and d.id=:produkId")
	public List<HargaNettoProdukByKelasD> findByKelasNProduk(@Param("kelasId") Integer kelasId,
			@Param("produkId") Integer produkId);

	@Query("select distinct hnd.hargaNetto1 " + "from HargaNettoProdukByKelasD hnd " + "inner join hnd.produk prd "
			+ "inner join hnd.kelas kls " + "where hnd.statusEnabled is true " + "and prd.statusEnabled is true "
			+ "and kls.statusEnabled is true " + "and hnd.komponenHargaId = :komponenHargaId "
			+ "and hnd.produkId = :produkId " + "and hnd.kelasId = :kelasId")
	public Optional<Double> findHargetNetto1Komponen(@Param("komponenHargaId") Integer idKomponenHarga,
			@Param("produkId") Integer idProduk, @Param("kelasId") Integer idKelas);
}
