package com.jasamedika.medifirst2000.dao.custom;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.jasamedika.medifirst2000.dao.custom.base.impl.CoreDaoImpl;
import com.jasamedika.medifirst2000.entities.IpsrsPreventiveMaintenance;

@Repository
public class IpsrsPreventiveMaintenanceDaoCustomImpl extends CoreDaoImpl<IpsrsPreventiveMaintenance> {

	public IpsrsPreventiveMaintenanceDaoCustomImpl() {
		super(IpsrsPreventiveMaintenance.class);
	}

	public Map<String, Object> getPerencanaan(String noRec){
		StringBuffer buffer = new StringBuffer();
		buffer.append("select NEW Map (");
		buffer.append("b.jenisPeriode as jenisPeriode) ");
		buffer.append("from IpsrsMaintenance a ");
		buffer.append("left join a.ipsrsKontakService b ");
		buffer.append("where a.noRec=:noRec ");
		
		Query query = em.createQuery(buffer.toString());
		query.setParameter("noRec", noRec);
		return (Map<String, Object>) query.getResultList();
	}
	
	public List<Map<String, Object>> get(String noRec){
		
		List<Map<String, Object>> listData = new ArrayList<>();
		
		Map<String, Object> getData = getPerencanaan(noRec);
		
		if(getData.get("jenisPeriode").toString().matches("Minggu")){
			
		} else if(getData.get("jenisPeriode").toString().matches("Bulanan")){
			
		} else if(getData.get("jenisPeriode").toString().matches("Tahunan")){
			
		}
		
		return listData;
	}
}
