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.dao.DetailTriaseDao;
import com.jasamedika.medifirst2000.entities.DetailTriase;
import com.jasamedika.medifirst2000.entities.Kelas;
import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.DetailTriaseService;
import com.jasamedika.medifirst2000.vo.DetailTriaseVO;

@Service("detailTriaseService")
public class DetailTriaseServiceImpl implements DetailTriaseService{
	
	@Autowired
	private DetailTriaseConverter detailTriaseConverter;
	
	@Autowired
	private DetailTriaseDao detailTriaseDao;

	@Override
	public DetailTriaseVO add(DetailTriaseVO vo) throws JpaSystemException, ServiceVOException {
		DetailTriase result = detailTriaseConverter.transferVOToModel(vo, new DetailTriase());
		DetailTriase resultModel=detailTriaseDao.save(result);
		DetailTriaseVO resultVo=new DetailTriaseVO();
		resultVo=detailTriaseConverter.transferModelToVO(resultModel, resultVo);
		return resultVo;
	}

	@Override
	public DetailTriaseVO update(DetailTriaseVO vo) throws JpaSystemException, ServiceVOException {
		DetailTriase kelas = detailTriaseDao.findOne(vo.getId());
		kelas=detailTriaseConverter.transferVOToModel(vo, kelas);
		
		detailTriaseDao.save(kelas);
		return vo;
	}

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

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

	@Override
	public List<DetailTriaseVO> findAll() throws JpaSystemException {
		List<DetailTriase> resultList = (List<DetailTriase>) detailTriaseDao.findAll();

		List<DetailTriaseVO> resultVOList = new ArrayList<DetailTriaseVO>();
		for (DetailTriase items : resultList) {
			DetailTriaseVO vo = new DetailTriaseVO();
			vo=detailTriaseConverter.transferModelToVO(items, vo);
			resultVOList.add(vo);
			
		}
		
		return resultVOList;
	}

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

	

	
}
