package com.jasamedika.medifirst2000.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jasamedika.medifirst2000.converter.BaseConverterImpl;
import com.jasamedika.medifirst2000.dao.PlanningPelayananSistemPetugasDao;
import com.jasamedika.medifirst2000.entities.JenisPetugasPelaksana;
import com.jasamedika.medifirst2000.entities.Pegawai;
import com.jasamedika.medifirst2000.entities.PlanningPelayananSistemPetugas;
import com.jasamedika.medifirst2000.entities.Produk;
import com.jasamedika.medifirst2000.entities.StrukOrder;
import com.jasamedika.medifirst2000.entities.StrukPlanning;
import com.jasamedika.medifirst2000.service.PlanningPelayananSistemPetugasService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.JenisPetugasPelaksanaVO;
import com.jasamedika.medifirst2000.vo.PegawaiVO;
import com.jasamedika.medifirst2000.vo.PlanningPelayananSistemPetugasVO;
import com.jasamedika.medifirst2000.vo.ProdukVO;
import com.jasamedika.medifirst2000.vo.StrukOrderVO;
import com.jasamedika.medifirst2000.vo.StrukPlanningVO;

@Service("PlanningPelayananSistemPetugasService")
public class PlanningPelayananSistemPetugasServiceImpl implements PlanningPelayananSistemPetugasService {
	@Autowired
	private PlanningPelayananSistemPetugasDao planningPelayananSistemPetugasDao; 
	
	
	@Autowired
	private BaseConverterImpl<PegawaiVO, Pegawai> pegawaiConverter;
	
	@Autowired
	private BaseConverterImpl<PlanningPelayananSistemPetugasVO, PlanningPelayananSistemPetugas> planningPelayananSistemConverter;
	
	@Autowired
	private BaseConverterImpl<ProdukVO, Produk> produkConverter;
	
	@Autowired
	private BaseConverterImpl<JenisPetugasPelaksanaVO, JenisPetugasPelaksana> jenisPetugasPeConverter;
	
	@Autowired
	private BaseConverterImpl<StrukOrderVO, StrukOrder> strukOrderConverter;
	
	@Autowired
	private BaseConverterImpl<StrukPlanningVO, StrukPlanning> strukPlanningConverter;
	
	@Override
	public Map<String, Object> savePlanningPelayananSisPetugas(PlanningPelayananSistemPetugasVO vo) {
		Map<String, Object> result = new HashMap<>();
		
		PlanningPelayananSistemPetugas ppsp = new PlanningPelayananSistemPetugas();
		ppsp = planningPelayananSistemConverter.transferVOToModel(vo, ppsp);
	
		if(CommonUtil.isNotNullOrEmpty(vo.getKdPegawai()) && vo.getKdPegawai().getId() != 0)  {
			ppsp.setKdPegawai(pegawaiConverter.transferVOToModel(vo.getKdPegawai(), new Pegawai()));
		}

		if (CommonUtil.isNotNullOrEmpty(vo.getKdNoPlanning())) {
			ppsp.setKdNoPlanning(strukPlanningConverter.transferVOToModel(vo.getKdNoPlanning(), new StrukPlanning()));
		}
		
		if (CommonUtil.isNotNullOrEmpty(vo.getKdNoOrder())) {
			ppsp.setKdNoOrder(strukOrderConverter.transferVOToModel(vo.getKdNoOrder(), new StrukOrder()));
		}
	
		if(CommonUtil.isNotNullOrEmpty(vo.getKdProduk()))  {
			ppsp.setKdProduk(produkConverter.transferVOToModel(vo.getKdProduk(), new Produk()));
		}
		
		if(CommonUtil.isNotNullOrEmpty(vo.getKdJenisPetugasPe()))  {
			ppsp.setKdJenisPetugasPe(jenisPetugasPeConverter.transferVOToModel(vo.getKdJenisPetugasPe(), new JenisPetugasPelaksana()));
		}
		
		if(CommonUtil.isNotNullOrEmpty(vo.getKdPegawaiExec()) && vo.getKdPegawaiExec().getId() != 0)  {
			ppsp.setKdPegawaiExec(pegawaiConverter.transferVOToModel(vo.getKdPegawaiExec(), new Pegawai()));
		}
		
		ppsp.setIsPetugasPePJawab(vo.getIsPetugasPePJawab());
		
		if(CommonUtil.isNotNullOrEmpty(ppsp)) {
			PlanningPelayananSistemPetugas ppspResult = planningPelayananSistemPetugasDao.save(ppsp);
			result.put("NoRec", ppspResult.getNoRec());
			
		}
		return result;
		
	}

	@Override
	public Map<String, Object> getPelayanSistemPetugas() {
		Map<String, Object> result = new HashMap<String, Object>();
		
		List<Map<String, Object>> data = this.planningPelayananSistemPetugasDao.getPelayanSistemPetugas();
		
		if (CommonUtil.isNotNullOrEmpty(data)) {
			result.put("data", data);
		}
		return result;
	}

}
