package com.jasamedika.medifirst2000.dao;

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.JenisTransaksi;
import com.jasamedika.medifirst2000.entities.Produk;

@Repository("JenisTransaksiDao")
public interface JenisTransaksiDao extends PagingAndSortingRepository<JenisTransaksi, Integer>{
	@Query("select model from JenisTransaksi model where model.jenisTransaksi=:jenisTransaksi")
	public JenisTransaksi findByJenisTransaksi(@Param("jenisTransaksi") String jenisTransaksi);

	@Query("select model from JenisTransaksi model where model.id=:id")
	public JenisTransaksi findById(@Param("id") Integer id);
	
	
	@Query("select new map(p.namaProduk as namaProduk,p.id as idProduk,jt.jenisTransaksi as jenisTransaksi,jt.metodeHargaNetto as metodeHargaNetto) "
			+ "from Produk p "
			+ "left join p.detailJenisProduk djp "
			+ "left join djp.jenisProduk jp "
			+ "left join jp.kelompokProduk kp "
			+ "left join kp.jenisTransaksi jt "
			+ "where p.id=:produkId")
	public Map<String, Object> metodePenenntuanHarga(@Param("produkId") Integer produkId);

	@Query("select new map(p.namaProduk as namaProduk,p.id as idProduk,jt.jenisTransaksi as jenisTransaksi,jt.metodeStokHargaNetto as metodeStokHargaNetto) "
			+ "from Produk p "
			+ "left join p.detailJenisProduk djp "
			+ "left join djp.jenisProduk jp "
			+ "left join jp.kelompokProduk kp "
			+ "left join kp.jenisTransaksi jt "
			+ "where p.id=:produkId")
	public Map<String, Object> metodePenenntuanStok(@Param("produkId") Integer produkId);
	
	@Query("select jt.produkRetur "
			+ "from Produk p "
			+ "left join p.detailJenisProduk djp "
			+ "left join djp.jenisProduk jp "
			+ "left join jp.kelompokProduk kp "
			+ "left join kp.jenisTransaksi jt "
			+ "where p.id=:produkId")
	public Produk produkRetur(@Param("produkId") Integer produkId);
	
	@Query("select new Map(model.id as id, model.jenisTransaksi as jenisTransaksi, model.kelasDefaultId as kelasDefaultId, model.kelompokPelayananId as kelompokPelayananId, "
			+ "model.produkCitoId as produkCitoId, model.produkDepositId as produkDepositId, model.produkReturId as produkReturId) "
			+ "from JenisTransaksi model where model.id = :jenisTransaksiId and model.statusEnabled is true")
	public Map<String, Object> getJenisTransaksiById(@Param("jenisTransaksiId") Integer jenisTransaksiId);

}
