package com.jasamedika.medifirst2000.service.impl;

import java.util.HashMap;
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.RiwayatAsupanMakanDao;
import com.jasamedika.medifirst2000.entities.AntrianPasienDiPeriksa;
import com.jasamedika.medifirst2000.entities.CaraPemberianSusuBayi;
import com.jasamedika.medifirst2000.entities.JenisIsapanAsi;
import com.jasamedika.medifirst2000.entities.PasienDaftar;
//import com.jasamedika.medifirst2000.dao.RiwayatPascaLahirDao;
import com.jasamedika.medifirst2000.entities.RiwayatAsupanMakan;
//import com.jasamedika.medifirst2000.entities.RiwayatPascaLahir;
import com.jasamedika.medifirst2000.entities.StatusYaTidak;
import com.jasamedika.medifirst2000.service.RiwayatAsupanMakanService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.AntrianPasienDiPeriksaVO;
import com.jasamedika.medifirst2000.vo.CaraPemberianSusuBayiVO;
import com.jasamedika.medifirst2000.vo.JenisIsapanAsiVO;
import com.jasamedika.medifirst2000.vo.PasienDaftarVO;
import com.jasamedika.medifirst2000.vo.RiwayatAsupanMakanVO;
//import com.jasamedika.medifirst2000.vo.RiwayatPascaLahirVO;
import com.jasamedika.medifirst2000.vo.StatusYaTidakVO;

@Service
public class RiwayatAsupanMakanServiceImpl implements RiwayatAsupanMakanService {
	
	@Autowired
	private RiwayatAsupanMakanDao riwayatAsupanMakanDao;
	
	@Autowired
	private BaseConverterImpl<RiwayatAsupanMakanVO, RiwayatAsupanMakan> riwayatAsupanMakanConverter;
	
	@Autowired
	private BaseConverterImpl<JenisIsapanAsiVO, JenisIsapanAsi> jenisIsapanAsiConverter;
	
	@Autowired
	private BaseConverterImpl<StatusYaTidakVO, StatusYaTidak> statusYaTidakConverter;
	
	@Autowired
	private BaseConverterImpl<CaraPemberianSusuBayiVO, CaraPemberianSusuBayi> caraPemberianSusuBayiConverter;
	
	@Autowired
	private BaseConverterImpl<AntrianPasienDiPeriksaVO, AntrianPasienDiPeriksa> pasienDaftarConverter;
	
	@Override
	public Map<String, Object> addRiwayatAsupanMakan(RiwayatAsupanMakanVO vo) {
		RiwayatAsupanMakan riwayatAsupanMakan = new RiwayatAsupanMakan();
		if(CommonUtil.isNotNullOrEmpty(vo)){
			riwayatAsupanMakan = riwayatAsupanMakanConverter.transferVOToModel(vo, new RiwayatAsupanMakan());
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getBayiMendapatImd())){
			riwayatAsupanMakan.setBayiMendapatImd(statusYaTidakConverter.transferVOToModel(vo.getBayiMendapatImd(), new StatusYaTidak()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getCaraPemberianSusuBayi())){
			riwayatAsupanMakan.setCaraPemberianSusuBayi(caraPemberianSusuBayiConverter.transferVOToModel(vo.getCaraPemberianSusuBayi(), new CaraPemberianSusuBayi()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getJenisIsapanAsi())){
			riwayatAsupanMakan.setJenisIsapanAsi(jenisIsapanAsiConverter.transferVOToModel(vo.getJenisIsapanAsi(), new JenisIsapanAsi()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getBuburSusuAtauNasi())){
			riwayatAsupanMakan.setBuburSusuAtauNasi(statusYaTidakConverter.transferVOToModel(vo.getBuburSusuAtauNasi(), new StatusYaTidak()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getNasiTimSaring())){
			riwayatAsupanMakan.setNasiTimSaring(statusYaTidakConverter.transferVOToModel(vo.getNasiTimSaring(), new StatusYaTidak()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getNasiLembek())){
			riwayatAsupanMakan.setNasiLembek(statusYaTidakConverter.transferVOToModel(vo.getNasiLembek(), new StatusYaTidak()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getNasiBiasa())){
			riwayatAsupanMakan.setNasiBiasa(statusYaTidakConverter.transferVOToModel(vo.getNasiBiasa(), new StatusYaTidak()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getPasienDaftar())){
			riwayatAsupanMakan.setPasien(pasienDaftarConverter.transferVOToModel(vo.getPasienDaftar(),new AntrianPasienDiPeriksa()));
		}
		
		RiwayatAsupanMakan resultModel = riwayatAsupanMakanDao.save(riwayatAsupanMakan);
		
		Map<String, Object> result = new HashMap<String, Object>();
		
		if(CommonUtil.isNotNullOrEmpty(resultModel)){
			result.put("id", resultModel.getNoRec());
		}
		
		return result;
	}

	@Override
	public Map<String, Object> updateRiwayatAsupanMakan(RiwayatAsupanMakanVO vo) {
		RiwayatAsupanMakan riwayatAsupanMakan = new RiwayatAsupanMakan();
		if(CommonUtil.isNotNullOrEmpty(vo)){
			riwayatAsupanMakan = riwayatAsupanMakanConverter.transferVOToModel(vo, new RiwayatAsupanMakan());
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getBayiMendapatImd())){
			riwayatAsupanMakan.setBayiMendapatImd(statusYaTidakConverter.transferVOToModel(vo.getBayiMendapatImd(), new StatusYaTidak()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getCaraPemberianSusuBayi())){
			riwayatAsupanMakan.setCaraPemberianSusuBayi(caraPemberianSusuBayiConverter.transferVOToModel(vo.getCaraPemberianSusuBayi(), new CaraPemberianSusuBayi()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getJenisIsapanAsi())){
			riwayatAsupanMakan.setJenisIsapanAsi(jenisIsapanAsiConverter.transferVOToModel(vo.getJenisIsapanAsi(), new JenisIsapanAsi()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getBuburSusuAtauNasi())){
			riwayatAsupanMakan.setBuburSusuAtauNasi(statusYaTidakConverter.transferVOToModel(vo.getBuburSusuAtauNasi(), new StatusYaTidak()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getNasiTimSaring())){
			riwayatAsupanMakan.setNasiTimSaring(statusYaTidakConverter.transferVOToModel(vo.getNasiTimSaring(), new StatusYaTidak()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getNasiLembek())){
			riwayatAsupanMakan.setNasiLembek(statusYaTidakConverter.transferVOToModel(vo.getNasiLembek(), new StatusYaTidak()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getNasiBiasa())){
			riwayatAsupanMakan.setNasiBiasa(statusYaTidakConverter.transferVOToModel(vo.getNasiBiasa(), new StatusYaTidak()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getPasienDaftar())){
			riwayatAsupanMakan.setPasien(pasienDaftarConverter.transferVOToModel(vo.getPasienDaftar(),new AntrianPasienDiPeriksa()));
		}
		
		RiwayatAsupanMakan resultModel = riwayatAsupanMakanDao.save(riwayatAsupanMakan);
		
		Map<String, Object> result = new HashMap<String, Object>();
		
		if(CommonUtil.isNotNullOrEmpty(resultModel)){
			result.put("id", resultModel.getNoRec());
		}
		
		return result;
	}

}
