package com.jasamedika.medifirst2000.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
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.ParameterKepuasanDao;
import com.jasamedika.medifirst2000.entities.ParameterKepuasan;
import com.jasamedika.medifirst2000.service.ParameterKepuasanService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.ParameterKepuasanVO;

@Service("ParameterKepuasanService")
public class ParameterKepuasanServiceImpl implements ParameterKepuasanService{
	
	@Autowired
	private ParameterKepuasanDao parameterKepuasanDao;
	
	@Autowired
	private BaseConverterImpl<ParameterKepuasanVO, ParameterKepuasan> parameterKepuasanConverter;
	
	@Override
	public Map<String, Object> addParameterKepuasan(ParameterKepuasanVO vo) {
		ParameterKepuasan parameterKepuasan = new ParameterKepuasan();
		if(CommonUtil.isNotNullOrEmpty(vo)){
			parameterKepuasan = parameterKepuasanConverter.transferVOToModel(vo, new ParameterKepuasan());
		}
		
		Map<String, Object> result = new HashMap<String,Object>();
		
		ParameterKepuasan resultModel = parameterKepuasanDao.save(parameterKepuasan);
		
		if(CommonUtil.isNotNullOrEmpty(resultModel)){
			result.put("id", resultModel.getId());
			result.put("name", resultModel.getName());
		}
		
		return result;
	}

	@Override
	public Map<String, Object> updateParameterKepuasan(ParameterKepuasanVO vo) {
		ParameterKepuasan parameterKepuasan = new ParameterKepuasan();
		if(CommonUtil.isNotNullOrEmpty(vo)){
			parameterKepuasan = parameterKepuasanConverter.transferVOToModel(vo, new ParameterKepuasan());
		}
		
		Map<String, Object> result = new HashMap<String,Object>();
		
		ParameterKepuasan resultModel = parameterKepuasanDao.save(parameterKepuasan);
		
		if(CommonUtil.isNotNullOrEmpty(resultModel)){
			result.put("id", resultModel.getId());
			result.put("name", resultModel.getName());
		}
		
		return result;
	}

	@Override
	public Map<String, Object> findAllParameterKepuasan() {
		List<ParameterKepuasan> list = new ArrayList<>();
		Map<String, Object> result = new HashMap<String,Object>();
		list = (List<ParameterKepuasan>) parameterKepuasanDao.findAll();
		
		if(CommonUtil.isNotNullOrEmpty(list)){
			result.put("data", list);
		}
		return result;
	}

}
