package com.jasamedika.medifirst2000.service.impl;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service;

import com.jasamedika.medifirst2000.converter.DataGeneralCheckUpConverter;
import com.jasamedika.medifirst2000.converter.GeneralCheckUpConverter;
import com.jasamedika.medifirst2000.dao.DataGeneralCheckUpDao;
import com.jasamedika.medifirst2000.dao.GeneralCheckUpDao;
import com.jasamedika.medifirst2000.entities.PapKeluhanTambahan;
import com.jasamedika.medifirst2000.entities.PapLaboratorium;
import com.jasamedika.medifirst2000.entities.RisikoKerjaRuangan;
import com.jasamedika.medifirst2000.entities.DataGeneralCheckUp;
import com.jasamedika.medifirst2000.entities.GeneralCheckUp;
import com.jasamedika.medifirst2000.entities.Ruangan;
import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.GeneralCheckUpService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.util.JsonUtil;
import com.jasamedika.medifirst2000.vo.DataGeneralCheckUpVO;
import com.jasamedika.medifirst2000.vo.GeneralCheckUpVO;
import com.jasamedika.medifirst2000.vo.PegawaiVO;
import com.jasamedika.medifirst2000.vo.RuanganVO;

/**
 * Implement class for GeneralCheckUpService
 * 
 * @author Askur
 */
@Service("GeneralCheckUpService")
public class GeneralCheckUpServiceImpl implements GeneralCheckUpService {
	@Autowired
	private GeneralCheckUpDao generalCheckUpDao;
	@Autowired
	private DataGeneralCheckUpDao dataGeneralCheckUpDao;
	@Autowired
	private GeneralCheckUpConverter generalCheckUpConverter;
	@Autowired
	private DataGeneralCheckUpConverter dataGeneralCheckUpConverter;
	
	@Override
	public Map<String,Object> addGeneralCheckUp(GeneralCheckUpVO vo) throws JpaSystemException, ServiceVOException {
		Map<String,Object> result=new HashMap<String,Object>();
		GeneralCheckUp model=generalCheckUpConverter.transferVOToModel(vo, new GeneralCheckUp());
		List<DataGeneralCheckUp> detail=new ArrayList<DataGeneralCheckUp>();
		for(DataGeneralCheckUpVO detailVo:vo.getDataGeneralCheckUpSet()){
			DataGeneralCheckUp data=dataGeneralCheckUpConverter.transferVOToModel(detailVo, new DataGeneralCheckUp());
			data.setGeneralCheckUp(model);
			detail.add(data);
		}
		model.getDataGeneralCheckUpSet().clear();
		model.getDataGeneralCheckUpSet().addAll(detail);

		GeneralCheckUp resultModel=generalCheckUpDao.save(model);
		if(CommonUtil.isNotNullOrEmpty(resultModel)){
			result.put("generalCheckUp", resultModel);
		}
		return result;
	}

	@Override
	public Map<String,Object> addDataGeneralCheckUp(DataGeneralCheckUpVO vo) throws JpaSystemException, ServiceVOException {
		Map<String,Object> result=new HashMap<String,Object>();
		DataGeneralCheckUp model=dataGeneralCheckUpConverter.transferVOToModel(vo, new DataGeneralCheckUp());
		DataGeneralCheckUp resultModel=dataGeneralCheckUpDao.save(model);
		if(CommonUtil.isNotNullOrEmpty(resultModel)){
			result.put("generalCheckUp", resultModel);
		}
		return result;
	}

	@Override
	public Map<String,Object> findByPegawaiId(Integer pegawaiId) {
		Map<String,Object> result=new HashMap<String,Object>();
		List<GeneralCheckUp> resultModel= generalCheckUpDao.findByPegawaiId(pegawaiId);
		if(CommonUtil.isNotNullOrEmpty(resultModel)){			
			try {
				result.put("data", JsonUtil.ToMaps(resultModel));
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
			result.put("dataFound", true);			
		}else{
			result.put("dataFound", false);
		}		
		return result;
	}

	@Override
	public Object add(Object vo) throws JpaSystemException, ServiceVOException {
		return null;
	}

	@Override
	public Object update(Object vo) throws JpaSystemException, ServiceVOException {
		return null;
	}

	@Override
	public Boolean delete(Object key) throws JpaSystemException {
		return null;
	}

	@Override
	public Object findById(Object key) throws JpaSystemException {
		return null;
	}

	@Override
	public List findAll() throws JpaSystemException {
		return null;
	}

	@Override
	public Map findAllWithPageAndLimitAndSortByAndDirectionParameter(Integer page, Integer limit, String sort,
			String dir) {
		return null;
	}

}
