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.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service;

import com.jasamedika.medifirst2000.converter.ProgramKerjaStrategisConverter;
import com.jasamedika.medifirst2000.dao.ProgramKerjaStrategisDao;
import com.jasamedika.medifirst2000.entities.ProgramKerjaStrategis;
import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.ProgramKerjaStrategisService;
import com.jasamedika.medifirst2000.vo.ProgramKerjaStrategisVO;

@Service("ProgramKerjaStrategisService")
public class ProgramKerjaStrategisServiceImpl extends BaseVoServiceImpl implements ProgramKerjaStrategisService{

	@Autowired
	private ProgramKerjaStrategisDao programDao;
	
	@Autowired
	private ProgramKerjaStrategisConverter programConverter;
	
	@Override
	public ProgramKerjaStrategisVO add(ProgramKerjaStrategisVO vo) throws JpaSystemException, ServiceVOException {
		return null;
	}

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

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

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

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

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

	@Override
	public Map<String, Object> findAll(Integer page, Integer take, String sort, String dir,
			Specification<ProgramKerjaStrategis> spec) {
		Direction direction=null;
		
		if(dir.equalsIgnoreCase("asc")){
			direction=Sort.Direction.ASC;
		}else{
			direction=Sort.Direction.DESC;
		}
		
		Pageable pageable = new PageRequest(page, take, direction, sort);
		Page<ProgramKerjaStrategis> resultPage = programDao.findAll(spec, pageable);
		List<ProgramKerjaStrategis> resultData = resultPage.getContent();
		return constructMapReturn(resultData, resultPage.getTotalElements(), resultPage.getTotalPages());
	}

	@Override
	public Map<String, Object> save(ProgramKerjaStrategisVO vo) {
		Map<String,Object> result = new HashMap<String,Object>();
		ProgramKerjaStrategis model = programConverter.transferVOToModel(vo, new ProgramKerjaStrategis());
		
		programDao.save(model);
		
		return result;
	}

}
