package com.jasamedika.medifirst2000.service.impl;

import java.util.ArrayList;
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.DetailTriaseConverter;
import com.jasamedika.medifirst2000.converter.PemeriksaanTriageConverter;
import com.jasamedika.medifirst2000.dao.DetailTriaseDao;
import com.jasamedika.medifirst2000.dao.PemeriksaanTriageDao;
import com.jasamedika.medifirst2000.entities.DetailTriase;
import com.jasamedika.medifirst2000.entities.Kelas;
import com.jasamedika.medifirst2000.entities.PemeriksaanTriage;
import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.DetailTriaseService;
import com.jasamedika.medifirst2000.service.PemeriksaanTriageService;
import com.jasamedika.medifirst2000.vo.DetailTriaseVO;
import com.jasamedika.medifirst2000.vo.PemeriksaanTriageVO;

@Service("pemeriksaanTriageService")
public class PemeriksaanTriageServiceImpl implements PemeriksaanTriageService{
	
	@Autowired
	private PemeriksaanTriageConverter pemeriksaanTriageConverter;
	
	@Autowired
	private PemeriksaanTriageDao pemeriksaanTriageDao;

	@Override
	public PemeriksaanTriageVO add(PemeriksaanTriageVO vo) throws JpaSystemException, ServiceVOException {
		PemeriksaanTriage result = pemeriksaanTriageConverter.transferVOToModel(vo, new PemeriksaanTriage());
		PemeriksaanTriage resultModel=pemeriksaanTriageDao.save(result);
		PemeriksaanTriageVO resultVo=new PemeriksaanTriageVO();
		resultVo=pemeriksaanTriageConverter.transferModelToVO(resultModel, resultVo);
		return resultVo;
	}

	@Override
	public PemeriksaanTriageVO update(PemeriksaanTriageVO vo) throws JpaSystemException, ServiceVOException {
		PemeriksaanTriage kelas = pemeriksaanTriageDao.findOne(vo.getId());
		kelas=pemeriksaanTriageConverter.transferVOToModel(vo, kelas);
		
		pemeriksaanTriageDao.save(kelas);
		return vo;
	}

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

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

	@Override
	public List<PemeriksaanTriageVO> findAll() throws JpaSystemException {
		List<PemeriksaanTriage> resultList = (List<PemeriksaanTriage>) pemeriksaanTriageDao.findAll();

		List<PemeriksaanTriageVO> resultVOList = new ArrayList<PemeriksaanTriageVO>();
		for (PemeriksaanTriage items : resultList) {
			PemeriksaanTriageVO vo = new PemeriksaanTriageVO();
			vo=pemeriksaanTriageConverter.transferModelToVO(items, vo);
			resultVOList.add(vo);
			
		}
		
		return resultVOList;
	}

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

	

	
}
